A little XSL help please?

D

Dennis

[[Sorry I couldn't think of a better subject for this rookie question.]]

In my .xml I have something like:

<root>
<parent>
...
<child>
<keynode>thekey</keynode>
</child>
</parent>
...
<parent>
<keynode>thekey</keynode>
<valuenode>thevalue</valuenode>
...
</parent>
</root>

In english, what I would like to do in my .xsl is this:

When processing each /root/parent/child, use the value of keynode
('thekey') to look up a /root/parent somewhere else in the .xml with a
keynode which matches ... and retrieve the corresponding valuenode
('thevalue').

Is this possible?

P.S. I can manage the xsl:for-each part.

TIA,
 
M

Martin Honnen

Dennis said:
[[Sorry I couldn't think of a better subject for this rookie question.]]

In my .xml I have something like:

<root>
<parent>
...
<child>
<keynode>thekey</keynode>
</child>
</parent>
...
<parent>
<keynode>thekey</keynode>
<valuenode>thevalue</valuenode>
...
</parent>
</root>

In english, what I would like to do in my .xsl is this:

When processing each /root/parent/child, use the value of keynode
('thekey') to look up a /root/parent somewhere else in the .xml with a
keynode which matches ... and retrieve the corresponding valuenode
('thevalue').

Is this possible?

Sure
<xsl:template match="root/parent/child">
<xsl:value-of select="../parent[keynode =
current()/keynode]/valuenode"/>
</xsl:template>
 
D

Dennis

Dennis said:
[[Sorry I couldn't think of a better subject for this rookie question.]]

In my .xml I have something like:

<root>
<parent>
...
<child>
<keynode>thekey</keynode>
</child>
</parent>
...
<parent>
<keynode>thekey</keynode>
<valuenode>thevalue</valuenode>
...
</parent>
</root>

In english, what I would like to do in my .xsl is this:

When processing each /root/parent/child, use the value of keynode
('thekey') to look up a /root/parent somewhere else in the .xml with a
keynode which matches ... and retrieve the corresponding valuenode
('thevalue').

Is this possible?

Sure
<xsl:template match="root/parent/child">
<xsl:value-of select="../parent[keynode =
current()/keynode]/valuenode"/>
</xsl:template>

Thanks! I'll give it a whirl...
 
M

Martin Honnen

Dennis said:
<xsl:template match="root/parent/child">
<xsl:value-of select="../parent[keynode =
current()/keynode]/valuenode"/>
</xsl:template>

Thanks! I'll give it a whirl...

Should be
<xsl:value-of select="../../parent[keynode = current()/keynode]/valuenode"/>
actually.
 
D

Dennis

Dennis said:
<xsl:template match="root/parent/child">
<xsl:value-of select="../parent[keynode =
current()/keynode]/valuenode"/>
</xsl:template>

Thanks! I'll give it a whirl...

Should be
<xsl:value-of select="../../parent[keynode = current()/keynode]/valuenode"/>
actually.

OK.

Can you recommend a good online resource for beginners. I have a
programming background so I pick up on things quickly. I have been using
www.w3schools.com and just googling for answers to my questions, but I
don't see anyplace that I would call a comprehensive reference site with
good examples.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top