nested loops and conditional statements

Discussion in 'XML' started by Porthos, Dec 29, 2004.

  1. Porthos

    Porthos Guest

    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
    ------------------------
    <!-- Irrelevant text abridged -->
    12.01.1899
    12.01.1899
    12.01.1899
     
    Porthos, Dec 29, 2004
    #1
    1. Advertising

  2. Porthos

    Joris Gillis Guest

    > 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,

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    Joris Gillis, Dec 30, 2004
    #2
    1. Advertising

  3. Porthos

    Porthos Guest

    Using variables did the trick. Thanks!
     
    Porthos, Dec 30, 2004
    #3
  4. Porthos

    Joris Gillis Guest

    > 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,

    --
    Joris Gillis
    Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    Joris Gillis, Feb 7, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jstreet10
    Replies:
    1
    Views:
    348
    Sean Ross
    Dec 3, 2003
  2. Balamurugan

    Loops Statements going infinite?....

    Balamurugan, Oct 15, 2007, in forum: VHDL
    Replies:
    1
    Views:
    439
  3. John Crichton
    Replies:
    6
    Views:
    282
    John Crichton
    Jul 12, 2010
  4. Me
    Replies:
    2
    Views:
    260
  5. Gregc.
    Replies:
    0
    Views:
    157
    Gregc.
    Aug 28, 2006
Loading...

Share This Page