473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XSLT question: How to lookup another tag's children in XSLT

Hi,
I have a newbie XSLT question. I have the following xml, and I would
like to
find out the children of feature element in each 'features' element.

i.e. for each <featuresI would like to look up what each feature
depends on and gerenate a text file. For example, in the following
file, I would like to find out feature A depends on A1 and A2 and
feature B depends on B1 and B2. And write that to a text file.

How can I do that in XSLT? I know I can loop thru the 'features'
element using "for-each" but how can I do the lookup ?

Thanks for any help.

<feature name="A">
<depends ="A1"/>
<depends ="A2"/>
</feature>

<feature name="B">
<depends ="B1"/>
<depends ="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>

Sep 16 '06 #1
18 2034


yi*****@gmail.com wrote:

How can I do that in XSLT? I know I can loop thru the 'features'
element using "for-each" but how can I do the lookup ?
You have not even shown a 'featutes' element. If you know xsl:for-each
why can't you use one xsl:for-each select="feature" and then inside that
another xsl:for-each select="depends"?
<depends ="A1"/>
^^^^^^^^^^^^^^^^
This is not even XML.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 17 '06 #2
yi*****@gmail.com wrote:
Hi,
I have a newbie XSLT question. I have the following xml
Your example is not XML. I suggest you redesign it so that it is.

Quite apart from that, you haven't shown us everything. You talk about
feature A depending on A1 and A2, but nowhere in your data is there
anything to say what A1 and A2 are.

You almost certainly don't need or want to "loop" through anything.
In XSLT, what you appear to want can be done much more simply with
templates.

But first you have to have a well-formed or valid XML document.

///Peter
--
XML FAQ: http://xml.silmaril.ie

and I would
like to
find out the children of feature element in each 'features' element.

i.e. for each <featuresI would like to look up what each feature
depends on and gerenate a text file. For example, in the following
file, I would like to find out feature A depends on A1 and A2 and
feature B depends on B1 and B2. And write that to a text file.

How can I do that in XSLT? I know I can loop thru the 'features'
element using "for-each" but how can I do the lookup ?

Thanks for any help.

<feature name="A">
<depends ="A1"/>
<depends ="A2"/>
</feature>

<feature name="B">
<depends ="B1"/>
<depends ="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
Sep 17 '06 #3

Martin Honnen wrote:
yi*****@gmail.com wrote:

How can I do that in XSLT? I know I can loop thru the 'features'
element using "for-each" but how can I do the lookup ?

You have not even shown a 'featutes' element. If you know xsl:for-each
why can't you use one xsl:for-each select="feature" and then inside that
another xsl:for-each select="depends"?
<depends ="A1"/>
^^^^^^^^^^^^^^^^
This is not even XML.
This is obviously a mistake. What he most probably meant is:

<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>

<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>

Sep 18 '06 #4
Jean-François Michaud wrote:
This is obviously a mistake. What he most probably meant is:
Granted, but trying to help folks based on a guess tends to be less than
productive.

yinglcs, if you're still looking for help, post a corrected description
of your problem.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Sep 18 '06 #5

yi*****@gmail.com wrote:
Hi,
I have a newbie XSLT question. I have the following xml, and I would
like to
find out the children of feature element in each 'features' element.

i.e. for each <featuresI would like to look up what each feature
depends on and gerenate a text file. For example, in the following
file, I would like to find out feature A depends on A1 and A2 and
feature B depends on B1 and B2. And write that to a text file.

How can I do that in XSLT? I know I can loop thru the 'features'
element using "for-each" but how can I do the lookup ?

Thanks for any help.

<feature name="A">
<depends ="A1"/>
<depends ="A2"/>
</feature>

<feature name="B">
<depends ="B1"/>
<depends ="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
You should, before anything else, know that XSLT is not procedural
language; it is a functional language. Certain things that you might be
familiar with under procedural languages (like incrementing a variable
for example) is not directly possible with the facilities the language
offers. You have to break the natural processing progression and use
recursions to accomplish this particular feat.

A quick look at what you are trying to accomplish makes me think that
you might have to go through this recursively to accomplish what you
want to do.

if you HAVE to use the features element, you might have to use a
template that matches the features element to then recursively process
the entire XML tree that you would feed in as a parameter to a
recursive template, outputting what you want as you are going down the
recursion.

if you DON'T HAVE to use features,

You can simply use something like this:

XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="feature">
<xsl:text>Feature </xsl:text><xsl:value-of select="@name" />
<xsl:text>Depends on </xsl:text>
<xsl:apply-templates />
</xsl:template>

<xsl:template match="depends">
<xsl:value-of select="@name" /><xsl:text</xsl:text>
</xsl:template>
</xsl:stylesheet>

The XML snippet that you posted is malformed though, so I took the
liberty of correcting it:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>

<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
</root>

I didn't test the code but this should fly :).

Regards
Jean-Francois Michaud

Sep 18 '06 #6

Joseph Kesselman wrote:
Jean-François Michaud wrote:
This is obviously a mistake. What he most probably meant is:

Granted, but trying to help folks based on a guess tends to be less than
productive.
Bah, not really. This is pretty straight forwards :). He just doesn't
know how to go about it.

[snip]

Regards
Jean-Francois Michaud

Sep 18 '06 #7
Thanks for everybody's help. And thanks Jean-François Michaud for
providing me an example.

Jean-François Michaud,
I tried you example, I have 2 questions:
1. How can I make the children element 'feature' of 'features' NOT
match this '<xsl:template match="feature">' in my xslt?

<?xml version="1.0" encoding="UTF-8"?>
<root>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>

<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
</root>

2. How can I just walk thru the children of 'features' and match each
one with this xml template? for example, if I only have :

<features>

<feature name="B"/>
</features>

I only print out
Feature BDepends on
B1
B2

where I have both:

<features>
<feature name="A"/>
<feature name="B"/>
</features>

I will print out both:
Feature ADepends on
A1
A2
Feature BDepends on
B1
B2

Jean-François Michaud wrote:
yi*****@gmail.com wrote:
Hi,
I have a newbie XSLT question. I have the following xml, and I would
like to
find out the children of feature element in each 'features' element.

i.e. for each <featuresI would like to look up what each feature
depends on and gerenate a text file. For example, in the following
file, I would like to find out feature A depends on A1 and A2 and
feature B depends on B1 and B2. And write that to a text file.

How can I do that in XSLT? I know I can loop thru the 'features'
element using "for-each" but how can I do the lookup ?

Thanks for any help.

<feature name="A">
<depends ="A1"/>
<depends ="A2"/>
</feature>

<feature name="B">
<depends ="B1"/>
<depends ="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>

You should, before anything else, know that XSLT is not procedural
language; it is a functional language. Certain things that you might be
familiar with under procedural languages (like incrementing a variable
for example) is not directly possible with the facilities the language
offers. You have to break the natural processing progression and use
recursions to accomplish this particular feat.

A quick look at what you are trying to accomplish makes me think that
you might have to go through this recursively to accomplish what you
want to do.

if you HAVE to use the features element, you might have to use a
template that matches the features element to then recursively process
the entire XML tree that you would feed in as a parameter to a
recursive template, outputting what you want as you are going down the
recursion.

if you DON'T HAVE to use features,

You can simply use something like this:

XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="feature">
<xsl:text>Feature </xsl:text><xsl:value-of select="@name" />
<xsl:text>Depends on </xsl:text>
<xsl:apply-templates />
</xsl:template>

<xsl:template match="depends">
<xsl:value-of select="@name" /><xsl:text</xsl:text>
</xsl:template>
</xsl:stylesheet>

The XML snippet that you posted is malformed though, so I took the
liberty of correcting it:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>

<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
</root>

I didn't test the code but this should fly :).

Regards
Jean-Francois Michaud
Sep 19 '06 #8
yi*****@gmail.com wrote:
1. How can I make the children element 'feature' of 'features' NOT
match this '<xsl:template match="feature">' in my xslt?
One of many ways would be to match on "/root/feature"

2. How can I just walk thru the children of 'features' and match each
one with this xml template?
Inside the template for features, use xsl:apply-templates to process its
children.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Sep 19 '06 #9

Joseph Kesselman wrote:
yi*****@gmail.com wrote:
1. How can I make the children element 'feature' of 'features' NOT
match this '<xsl:template match="feature">' in my xslt?

One of many ways would be to match on "/root/feature"
To be more precise, what you would have to say to eliminate processing
of feature in features, what you would have to specify is that you want
the templates to do nothing when they encounter those specific
elements. As Joseph specified, you would reference feature within
features like this.

<xsl:template match="features/feature">
</xsl:template>

The template being empty makes it so that those particular feature
elements from the source XML tree will get dropped on the way to the
result XML tree.
2. How can I just walk thru the children of 'features' and match each
one with this xml template?

Inside the template for features, use xsl:apply-templates to process its
children.
As Joseph said, if you specify the above template, using this template
also will make it so that when features is encountered, its children
will be processed using already defined templates:

<xsl:template match="features">
<xsl:apply-templates />
</xsl:template>

As things get more complex, you might have to specify priorities for
your templates if you have many templates "talking" about the same
element but under different conditions. If you want to be certain that
the feature element doesn't get processed by the wrong feature
template, you would set down a priority on the one you want executed in
priority. Like this:

<xsl:template match="features/feature" priority="1">
</xsl:template>

On a side note, unless you want to specify in the "features" element
less feature elements to be processed than the total amount of
"expanded" feature elements (feature containing depends) present in
your XML, then the "features" construct is probably not relevant. But
then again, I don't really know what you are trying to accomplish. If
you were to specify less feature elements to be processed in features
than the total amount of expanded feature elements, then you might have
to look at more complex logic revolving around features using recursive
templates.

Hope this helps :).

Regards
Jean-Francois Michaud

Sep 21 '06 #10

yi*****@gmail.com wrote:
Thanks for everybody's help. And thanks Jean-François Michaud for
providing me an example.

Jean-François Michaud,
I tried you example, I have 2 questions:
1. How can I make the children element 'feature' of 'features' NOT
match this '<xsl:template match="feature">' in my xslt?

<?xml version="1.0" encoding="UTF-8"?>
<root>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>

<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
</root>

2. How can I just walk thru the children of 'features' and match each
one with this xml template? for example, if I only have :

<features>

<feature name="B"/>
</features>

I only print out
Feature BDepends on
B1
B2

where I have both:

<features>
<feature name="A"/>
<feature name="B"/>
</features>

I will print out both:
Feature ADepends on
A1
A2
Feature BDepends on
B1
B2
And this is where the $^@! hit the fan under XSLT. The language doesn't
naturally lend itself naturally to certain forms of non hierarchical
processing.

Since your features element is hierarchically dissociated structurally
from the extended feature element, there is no easy way to take care of
this other than passing down the whole XML source tree as a parameter
to other template processing (maybe even using a named template instead
of a match template.

What you will want to do is pass down the whole XML source tree as a
parameter down to the features and have template process each feature
within features using the source XML tree passed as a parameter to do
your processing. This form of processing will somewhat break the
normal flow of XSLT so be very thorough with your logic.

You might be able to get away with this by simply referencing the
parent nodes under a for-each in features also.

To make things very easy, if you were to structure things this way in
your XML (if you can), all the problems would dissapear:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<features>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>
<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>
</features>
</root>

Features contains individual feature which depends on certain things

Your XSLT templates would clearly be simplified. The idea would be to
only have features contain the feature that you want to display.

[snip]

Regards
Jean-Francois Michaud

Sep 21 '06 #11
Jean-François, Joseph,

Thanks for your help. I need to think about it further about what you
guys teach me.
But the problem is, I can't do this suggestion from Jean-François:
To make things very easy, if you were to structure things this way in
your XML (if you can),

Thank you again.
Jean-François Michaud wrote:
yi*****@gmail.com wrote:
Thanks for everybody's help. And thanks Jean-François Michaud for
providing me an example.

Jean-François Michaud,
I tried you example, I have 2 questions:
1. How can I make the children element 'feature' of 'features' NOT
match this '<xsl:template match="feature">' in my xslt?

<?xml version="1.0" encoding="UTF-8"?>
<root>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>

<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
</root>

2. How can I just walk thru the children of 'features' and match each
one with this xml template? for example, if I only have :

<features>

<feature name="B"/>
</features>

I only print out
Feature BDepends on
B1
B2

where I have both:

<features>
<feature name="A"/>
<feature name="B"/>
</features>

I will print out both:
Feature ADepends on
A1
A2
Feature BDepends on
B1
B2

And this is where the $^@! hit the fan under XSLT. The language doesn't
naturally lend itself naturally to certain forms of non hierarchical
processing.

Since your features element is hierarchically dissociated structurally
from the extended feature element, there is no easy way to take care of
this other than passing down the whole XML source tree as a parameter
to other template processing (maybe even using a named template instead
of a match template.

What you will want to do is pass down the whole XML source tree as a
parameter down to the features and have template process each feature
within features using the source XML tree passed as a parameter to do
your processing. This form of processing will somewhat break the
normal flow of XSLT so be very thorough with your logic.

You might be able to get away with this by simply referencing the
parent nodes under a for-each in features also.

To make things very easy, if you were to structure things this way in
your XML (if you can), all the problems would dissapear:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<features>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>
<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>
</features>
</root>

Features contains individual feature which depends on certain things

Your XSLT templates would clearly be simplified. The idea would be to
only have features contain the feature that you want to display.

[snip]

Regards
Jean-Francois Michaud
Sep 22 '06 #12
Thanks for all the help. However, I need more help.

Basically, I would like to get each 'feature' child of 'features' and

For example, for this input:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>

<feature name="B">
<depends name="B1"/>
</feature>

<feature name="C">
<depends name="C1"/>
<depends name="C2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
</root>

I would like to generate this output:
Feature A Depends on A1
Feature A Depends on A2

Feature B Depends on B1
Here is my xslt:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/features">
<xsl:for-each select="feature">
<xsl:call-template name="feature">

</xsl:call-template>
</xsl:for-each>
</xsl:template>

<xsl:template name="feature">
<xsl:param name="dummy" />
<xsl:text>Feature </xsl:text><xsl:value-of select="@name"
/>
<xsl:text>Depends on </xsl:text>

</xsl:if>
</xsl:template>

<xsl:template match="depends">
<xsl:value-of select="@name" /><xsl:text</xsl:text>
</xsl:template>
</xsl:stylesheet>
But this just match each 'feature' element in the source.

My questions are:

1. if I do this:
<xsl:template name="feature"... </xsl:template>
intead of
<xsl:template match="feature"... </xsl:template>

I don't match any 'feature' element. But the output show that i only
match the 'feature'. Here is the xslt output. That is not i would like
to accomplish.
A1
A2

B1
B2

C1
C2

2. Why this does not match anything? I expect this will loop thru each
children of "features" and call the name template 'feature'. But
apparently, I did something wrong.

<xsl:template match="/features">
<xsl:for-each select="feature">
<xsl:call-template name="feature">

</xsl:call-template>
</xsl:for-each>
</xsl:template>

I appreciate if anyone can give me more help.

Thank you.
yi*****@gmail.com wrote:
Jean-François, Joseph,

Thanks for your help. I need to think about it further about what you
guys teach me.
But the problem is, I can't do this suggestion from Jean-François:
To make things very easy, if you were to structure things this way in
your XML (if you can),


Thank you again.
Jean-François Michaud wrote:
yi*****@gmail.com wrote:
Thanks for everybody's help. And thanks Jean-François Michaud for
providing me an example.
>
Jean-François Michaud,
I tried you example, I have 2 questions:
1. How can I make the children element 'feature' of 'features' NOT
match this '<xsl:template match="feature">' in my xslt?
>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>
>
<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>
>
<features>
<feature name="A"/>
<feature name="B"/>
</features>
</root>
>
2. How can I just walk thru the children of 'features' and match each
one with this xml template? for example, if I only have :
>
<features>
>
<feature name="B"/>
</features>
>
I only print out
Feature BDepends on
B1
B2
>
where I have both:
>
<features>
<feature name="A"/>
<feature name="B"/>
</features>
>
I will print out both:
Feature ADepends on
A1
A2
>
>
Feature BDepends on
B1
B2
And this is where the $^@! hit the fan under XSLT. The language doesn't
naturally lend itself naturally to certain forms of non hierarchical
processing.

Since your features element is hierarchically dissociated structurally
from the extended feature element, there is no easy way to take care of
this other than passing down the whole XML source tree as a parameter
to other template processing (maybe even using a named template instead
of a match template.

What you will want to do is pass down the whole XML source tree as a
parameter down to the features and have template process each feature
within features using the source XML tree passed as a parameter to do
your processing. This form of processing will somewhat break the
normal flow of XSLT so be very thorough with your logic.

You might be able to get away with this by simply referencing the
parent nodes under a for-each in features also.

To make things very easy, if you were to structure things this way in
your XML (if you can), all the problems would dissapear:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<features>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>
<feature name="B">
<depends name="B1"/>
<depends name="B2"/>
</feature>
</features>
</root>

Features contains individual feature which depends on certain things

Your XSLT templates would clearly be simplified. The idea would be to
only have features contain the feature that you want to display.

[snip]

Regards
Jean-Francois Michaud
Oct 1 '06 #13

Please don't top-post.

yi*****@gmail.com wrote:
For example, for this input:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<feature name="A">
<depends name="A1"/>
<depends name="A2"/>
</feature>

<feature name="B">
<depends name="B1"/>
</feature>

<feature name="C">
<depends name="C1"/>
<depends name="C2"/>
</feature>

<features>
<feature name="A"/>
<feature name="B"/>
</features>
</root>

I would like to generate this output:
Feature A Depends on A1
Feature A Depends on A2

Feature B Depends on B1

Here is my xslt:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
What about the output method? (And XML declaration, for
that matter.) Since you seem to be trying to output text,
perhaps you should give a hint about that to your XSLT
processor - and to other people's XSLT processors?
<xsl:template match="/features">
<xsl:for-each select="feature">
Why?
<xsl:call-template name="feature">
</xsl:call-template>
I don't believe that's what <xsl:call-templateis for.
</xsl:for-each>
</xsl:template>

<xsl:template name="feature">
And what's that supposed to match?
<xsl:param name="dummy" />
<xsl:text>Feature </xsl:text>
<xsl:value-of select="@name" />
<xsl:text>Depends on </xsl:text>
</xsl:if>
That's not even well-formed.
</xsl:template>

<xsl:template match="depends">
<xsl:value-of select="@name" />
<xsl:text</xsl:text>
</xsl:template>
And how's that supposed to work?
</xsl:stylesheet>

But this just match each 'feature' element in the source.
No, it matches all the <dependselements in your XML,
because your third template is the only one that actually
does anything. Try removing the first two templates, and
you'll get exactly the same result.
1. if I do this:
<xsl:template name="feature"... </xsl:template>
intead of
<xsl:template match="feature"... </xsl:template>

I don't match any 'feature' element.
Precisely. You don't match anything. So the template
doesn't do anything.
But the output show that i only match the 'feature'.
No, it doesn't. It shows something entirely different. See
above.
Here is the xslt output. That is not i would like
to accomplish.
A1
A2

B1
B2

C1
C2
For that matter, it's NOT the XSLT output, either. First,
your XSLT is not well-formed, and even if it were
well-formed, there's no sign of B2 anywhere in the XML.
(But that's to be expected; B2's are supposed to be
awfully stealthy, after all.)

If you really want to get help on the newsgroup, I'd
heartily recommend posting your actual code, as well as
actual examples of your input/output. It seems just a bit
disrespectful -- you're asking people for help, but you
can't be bothered to weed out even the most obvious bugs
(such as that </xsl:if>) in your code.

No one's asking you to post your production code or
anything. Just spend a minute or two making sure what
you're posting is relevant to your question. I spent five
minutes of my Sunday morning straightening out your WAG's,
and if I started tinkering with your code in a pretty
cheerful mood, I'm now feeling quite murderous.
2. Why this does not match anything? I expect this will
loop thru each children of "features" and call the name
template 'feature'. But apparently, I did something
wrong.
That's not how it works. But since you couldn't be bothered
to double-check what you post, I can't be bothered to
explain that in detail to you. Read the spec. Or the
reference. Whatever.

The following works, but you'll just have to figure out why
yourself. It'll do you a world of good, I think.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/features">
<xsl:apply-templates select="feature"/>
</xsl:template>
<xsl:template match="features/feature">
<xsl:apply-templates
select="/root/feature[@name=current()/@name]/depends"
mode="list-dependencies">
<xsl:with-param name="p-node" select="."/>
</xsl:apply-templates>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="depends" mode="list-dependencies">
<xsl:param name="p-node"/>
<xsl:text>Feature </xsl:text>
<xsl:value-of select="$p-node/@name"/>
<xsl:textdepends on </xsl:text>
<xsl:value-of select="@name"/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>

--
roy axenov

Oct 1 '06 #14
Roy: you might want to look up the description of named templates, since
you're off-base on that point.

yinglcs: He does have a point; you'll get more and better help if you
don't post obviously sloppy examples.

<xsl:template name="feature"... </xsl:template>
intead of
<xsl:template match="feature"... </xsl:template>
I don't match any 'feature' element.
If you want the template to be executed by apply-templates matching, you
must use match= with a match pattern. If you want it to run when you
invoke it explicitly by name with call-template, you must use name= with
a literal name. If you want the same template to be invoked both ways,
you need to specify both. In this case, you seem to want it running only
with call-template, though I don't quite see why you're doing it that way.
>2. Why this does not match anything? I expect this will loop thru each
children of "features" and call the name template 'feature'. But
apparently, I did something wrong.
<xsl:template match="/features">
/features matches <featuresif and only if it's the outermost element
(child of root). Get rid of the /.
Oct 1 '06 #15

Joe Kesselman wrote:
yinglcs wrote:
Roy: you might want to look up the description of named
templates, since you're off-base on that point.
Thanks for the pointer, I'm just starting with XSLT myself.
(I have a feeling I'm going to need it soon, so I'm trying
to be prepared ahead of time.)
<?xml version="1.0" encoding="UTF-8"?>
<root>
. . .
<features>
. . .
</features>
</root>

2. Why this does not match anything? I expect this will
loop thru each children of "features" and call the name
template 'feature'. But apparently, I did something
wrong.
<xsl:template match="/features">

/features matches <featuresif and only if it's the
outermost element (child of root). Get rid of the /.
Oh, I completely missed that. That's the problem with the
XSLT I posted, too. It works (sort of), but the first
template doesn't actually match anything because of this
bug.

--
roy axenov

Oct 1 '06 #16
Roy, Joe,

Thanks for your help.

Roy,
As you said you start learning XSLT yourself, can you please tell me
what do you read to learn XSLT?

Thank you.
roy axenov wrote:
Joe Kesselman wrote:
yinglcs wrote:
Roy: you might want to look up the description of named
templates, since you're off-base on that point.

Thanks for the pointer, I'm just starting with XSLT myself.
(I have a feeling I'm going to need it soon, so I'm trying
to be prepared ahead of time.)
<?xml version="1.0" encoding="UTF-8"?>
<root>
. . .
<features>
. . .
</features>
</root>
>
2. Why this does not match anything? I expect this will
loop thru each children of "features" and call the name
template 'feature'. But apparently, I did something
wrong.
<xsl:template match="/features">
/features matches <featuresif and only if it's the
outermost element (child of root). Get rid of the /.

Oh, I completely missed that. That's the problem with the
XSLT I posted, too. It works (sort of), but the first
template doesn't actually match anything because of this
bug.

--
roy axenov
Oct 2 '06 #17

A: Because it messes up the order in which people normally
read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on USENET?

yi*****@gmail.com wrote:
roy axenov wrote:
Joe Kesselman wrote:
[named templates]
Roy: you might want to look up the description of
named templates, since you're off-base on that point.
Thanks for the pointer, I'm just starting with XSLT
myself. (I have a feeling I'm going to need it soon, so
I'm trying to be prepared ahead of time.)
As you said you start learning XSLT yourself, can you
please tell me what do you read to learn XSLT?
comp.text.xml, naturally. Lots of problems to solve here,
and lots of useful hints, too.

Now that I think of it, a short XSLT/XPath reference on
developer.mozilla.org has been quite helpful.

W3C recommendations are probably worth reading. They tend
to put me to sleep in a couple of minutes or so, though.

--
roy axenov

Oct 3 '06 #18
W3C recommendations are probably worth reading. They tend
to put me to sleep in a couple of minutes or so, though.
If you're looking for something nearly as authoritative as the W3C spec,
but readable by folks who aren't Language Lawyers, Mike Kay's tome on
XSLT is still a remarkably good reference. Definitely something a
beginner should have available, but probably not the place to start
learning.

If what you're looking for is tutorial material, I can't advise you on
books. Do I need to plug IBM's XML DeveloperWorks website yet again?
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Oct 3 '06 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Luke Dalessandro | last post by:
I have some XML data that has mixed content XML tags that embed XHTML tags, for instance: <note>Somebody wrote this note in XHTML and wanto to <a href="link.html" target="_new">link</a> to a...
5
by: Jay | last post by:
I have a document as follows: <graphics> <graphic> <tag> <parameter/> </tag> <tag> <parameter/> </tag>
6
by: Per Jørgen Vigdal | last post by:
I have a XML that I need to map. The XML goes like: <Children> <Child> <References> <External> <Reference name="filename" value="1.dat"/> <Reference name="invoicenr" value="1111111"/>...
0
by: Christopher M. Lauer | last post by:
I have done my best to answer this question but can not find the proper set of commands. I would like to transform an xml file (in code behind) and display its output in a specific html tag,...
2
by: Richard L Rosenheim | last post by:
Is it possible to include addition tags in a XSLT file, that the XSLT processor will, for all practical purposes, ignore? What I'm looking to do is to include a section to contain information...
1
by: arnold | last post by:
Hi, I've been knocking my head against the wall trying to create an XSL transform to perform "normalizations" of a set of XML files that have a common structure. % XML file before transform
2
by: Gabe Moothart | last post by:
Hi, I need some help figuring out how to do something in xslt. I have an xml document with a list of items. Each item in turn can have a list of options, like so: <item> <stuff>Item 1...
3
by: gregmcmullinjr | last post by:
Hi All, I would like to use XSLT to replace all <unodes that are children of a <bnode with a new <headingnode. Also, if the <bnode has no other children than remove it as well. For example: ...
8
by: Hercules Dev. | last post by:
Hi all, I'm new in xslt and xpath, so my question might be simple but i'm learning. I have an XML document and need to transform it into another XML, I use xslt and it works, but there is a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.