nested loops and conditional statements

P

Porthos

Here's yet another question. Thanks for your patience/advice. I am
trying to match attributes from different paths in different files and
display an attribute of the subordinate tag in the second file when
they match. But I seem to only get the last value of that subordinate
tag attribute over and over. Any thoughts? I'm pretty sure that the
problem lies in my referencing absolouts paths from the 'when' tag.

-James

Document 1 (doc1.xml)
------------------------
<AA>
<BB author="McFly">
<CC title="Back to the Future">00-00-00-01</CC>
</BB>
<BB author="Bartakamous">
<CC title="Perfect Strangers">00-00-00-02</CC>
</BB>
</AA>

Document 2 (doc2.xml)
------------------------
<MM>
<NN author="McFly">
<OO dob="08.25.1980">
<!-- Additional Unrelated Tags -->
</OO>
</NN>
<NN author="Bartakamous">
<OO dob="02.15.1962">
<!-- Additional Unrelated Tags -->
</OO>
</NN>
<NN author="Mclain">
<OO dob="12.01.1899">
<!-- Additional Unrelated Tags -->
</OO>
</NN>
</MM>

XSL Document
------------------------
<xsl:for-each select="AA/BB">
<!-- Unrelated processing instructions -->
<xsl:for-each select"AA/BB>
<!-- Unrelated processing instructions -->
<xsl:for-each select="CC/@title">
<xsl:for-each select="document('doc2.xml')/MM">
<!-- Unrelated processing instructions -->
<xsl:choose>
<xsl:when test="document('doc1.xml')/AA/BB/@author=@author">
<xsl:value-of select="NN/OO/@dob"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>


Result
 
J

Joris Gillis

Here's yet another question. Thanks for your patience/advice. I am
trying to match attributes from different paths in different files and
display an attribute of the subordinate tag in the second file when
they match. But I seem to only get the last value of that subordinate
tag attribute over and over. Any thoughts? I'm pretty sure that the
problem lies in my referencing absolouts paths from the 'when' tag.

Hi,

Your xslt snippet doesn't seem to be working.

Try this:
<xsl:for-each select="AA/BB">
<xsl:variable name="author" select="@author"/>
<!-- Unrelated processing instructions -->
<xsl:for-each select="CC/@title">

<xsl:for-each select="document('doc2.xml')/MM/NN">
<!-- Unrelated processing instructions -->
<xsl:choose>
<xsl:when test="$author=@author">
<xsl:value-of select="OO/@dob"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>

regards,
 
J

Joris Gillis

Here's yet another question. Thanks for your patience/advice. I am
trying to match attributes from different paths in different files and
display an attribute of the subordinate tag in the second file when
they match. But I seem to only get the last value of that subordinate
tag attribute over and over. Any thoughts? I'm pretty sure that the
problem lies in my referencing absolouts paths from the 'when' tag.

Hi,

Your xslt snippet doesn't seem to be working.

Try this:
<xsl:for-each select="AA/BB">
<xsl:variable name="author" select="@author"/>
<!-- Unrelated processing instructions -->
<xsl:for-each select="CC/@title">

<xsl:for-each select="document('doc2.xml')/MM/NN">
<!-- Unrelated processing instructions -->
<xsl:choose>
<xsl:when test="$author=@author">
<xsl:value-of select="OO/@dob"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>

regards,
 

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

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,244
Members
46,838
Latest member
KandiceChi

Latest Threads

Top