Nested FOR - EACH PROBLEM

Discussion in 'XML' started by Pheckz, Jan 6, 2005.

  1. Pheckz

    Pheckz Guest

    Hi I have a nested for each but it does not display my desire output


    Here is the xml:



    <?xml version="1.0" standalone="yes"?>
    <NewDataSet>
    <Table>

    <assoc_type>BD</assoc_type>
    <assoc_ofc>hong kong </assoc_ofc>
    <assoc_initial>FB </assoc_initial>
    <rcv_rcvl>2</rcv_rcvl>
    <gyear>2002</gyear>
    <doc_positionID>875000048</doc_positionID>
    <doc_id>875000038</doc_id>
    <source>1</source>
    <inv_main_id>877000032</inv_main_id>
    </Table>
    <Table>

    <assoc_type>BD</assoc_type>
    <assoc_ofc>hong kong </assoc_ofc>
    <assoc_initial>FR </assoc_initial>
    <rcv_rcvl>2</rcv_rcvl>
    <gyear>2002</gyear>
    <doc_positionID>875000048</doc_positionID>
    <doc_id>875000038</doc_id>
    <source>1</source>
    <inv_main_id>877000032</inv_main_id>
    </Table>
    <Table>

    <assoc_type>BD</assoc_type>
    <assoc_ofc>hong kong </assoc_ofc>
    <assoc_initial>FC </assoc_initial>
    <rcv_rcvl>2</rcv_rcvl>
    <gyear>2002</gyear>
    <doc_positionID>875000048</doc_positionID>
    <doc_id>875000038</doc_id>
    <source>1</source>
    <inv_main_id>877000032</inv_main_id>
    </Table>

    <NewDataSet>


    the xslt is:



    <xsl:for-each select="NewDataSet/Table[inv_main_id[not(. =
    preceding::inv_main_id)] and assoc_type='BD' and gyear='2002' and
    rcv_rcvl='2']">
    <xsl:variable name="Vinv_main_id">
    <xsl:value-of select="inv_main_id"/>
    </xsl:variable>

    <td><xsl:value-of select="gyear"/></td>
    <xsl:for-each

    select="NewDataSet/Table[inv_main_id=$Vinv_main_id]">
    <td><xsl:value-of select="assoc_initial"/></TD>
    </xsl:for-each
    </xsl:for-each

    this is what the output should
    be:


    2002 FBFRFC


    however it did not displayed any problems but the output is only:


    2002


    it seems it doesn't execute the second for-each loop.
    Thanks in advance
     
    Pheckz, Jan 6, 2005
    #1
    1. Advertising

  2. Pheckz

    Pheckz Guest

    I solve this using:
    <xsl:for-each select="document('rcv.xml')/DATASET/.....">


    Pheckz wrote:
    > Hi I have a nested for each but it does not display my desire output
    >
    >
    > Here is the xml:
    >
    >
    >
    > <?xml version="1.0" standalone="yes"?>
    > <NewDataSet>
    > <Table>
    >
    > <assoc_type>BD</assoc_type>
    > <assoc_ofc>hong kong </assoc_ofc>
    > <assoc_initial>FB </assoc_initial>
    > <rcv_rcvl>2</rcv_rcvl>
    > <gyear>2002</gyear>
    > <doc_positionID>875000048</doc_positionID>
    > <doc_id>875000038</doc_id>
    > <source>1</source>
    > <inv_main_id>877000032</inv_main_id>
    > </Table>
    > <Table>
    >
    > <assoc_type>BD</assoc_type>
    > <assoc_ofc>hong kong </assoc_ofc>
    > <assoc_initial>FR </assoc_initial>
    > <rcv_rcvl>2</rcv_rcvl>
    > <gyear>2002</gyear>
    > <doc_positionID>875000048</doc_positionID>
    > <doc_id>875000038</doc_id>
    > <source>1</source>
    > <inv_main_id>877000032</inv_main_id>
    > </Table>
    > <Table>
    >
    > <assoc_type>BD</assoc_type>
    > <assoc_ofc>hong kong </assoc_ofc>
    > <assoc_initial>FC </assoc_initial>
    > <rcv_rcvl>2</rcv_rcvl>
    > <gyear>2002</gyear>
    > <doc_positionID>875000048</doc_positionID>
    > <doc_id>875000038</doc_id>
    > <source>1</source>
    > <inv_main_id>877000032</inv_main_id>
    > </Table>
    >
    > <NewDataSet>
    >
    >
    > the xslt is:
    >
    >
    >
    > <xsl:for-each select="NewDataSet/Table[inv_main_id[not(. =
    > preceding::inv_main_id)] and assoc_type='BD' and gyear='2002' and
    > rcv_rcvl='2']">
    > <xsl:variable name="Vinv_main_id">
    > <xsl:value-of select="inv_main_id"/>
    > </xsl:variable>
    >
    > <td><xsl:value-of select="gyear"/></td>
    > <xsl:for-each
    >
    > select="NewDataSet/Table[inv_main_id=$Vinv_main_id]">
    > <td><xsl:value-of select="assoc_initial"/></TD>
    > </xsl:for-each
    > </xsl:for-each
    >
    > this is what the output should
    > be:
    >
    >
    > 2002 FBFRFC
    >
    >
    > however it did not displayed any problems but the output is only:
    >
    >
    > 2002
    >
    >
    > it seems it doesn't execute the second for-each loop.
    > Thanks in advance
     
    Pheckz, Jan 6, 2005
    #2
    1. Advertising

  3. Pheckz

    Pheckz Guest

    I solve this using:
    <xsl:for-each select="document('rcv.xml')/DATASET/.....">


    Pheckz wrote:
    > Hi I have a nested for each but it does not display my desire output
    >
    >
    > Here is the xml:
    >
    >
    >
    > <?xml version="1.0" standalone="yes"?>
    > <NewDataSet>
    > <Table>
    >
    > <assoc_type>BD</assoc_type>
    > <assoc_ofc>hong kong </assoc_ofc>
    > <assoc_initial>FB </assoc_initial>
    > <rcv_rcvl>2</rcv_rcvl>
    > <gyear>2002</gyear>
    > <doc_positionID>875000048</doc_positionID>
    > <doc_id>875000038</doc_id>
    > <source>1</source>
    > <inv_main_id>877000032</inv_main_id>
    > </Table>
    > <Table>
    >
    > <assoc_type>BD</assoc_type>
    > <assoc_ofc>hong kong </assoc_ofc>
    > <assoc_initial>FR </assoc_initial>
    > <rcv_rcvl>2</rcv_rcvl>
    > <gyear>2002</gyear>
    > <doc_positionID>875000048</doc_positionID>
    > <doc_id>875000038</doc_id>
    > <source>1</source>
    > <inv_main_id>877000032</inv_main_id>
    > </Table>
    > <Table>
    >
    > <assoc_type>BD</assoc_type>
    > <assoc_ofc>hong kong </assoc_ofc>
    > <assoc_initial>FC </assoc_initial>
    > <rcv_rcvl>2</rcv_rcvl>
    > <gyear>2002</gyear>
    > <doc_positionID>875000048</doc_positionID>
    > <doc_id>875000038</doc_id>
    > <source>1</source>
    > <inv_main_id>877000032</inv_main_id>
    > </Table>
    >
    > <NewDataSet>
    >
    >
    > the xslt is:
    >
    >
    >
    > <xsl:for-each select="NewDataSet/Table[inv_main_id[not(. =
    > preceding::inv_main_id)] and assoc_type='BD' and gyear='2002' and
    > rcv_rcvl='2']">
    > <xsl:variable name="Vinv_main_id">
    > <xsl:value-of select="inv_main_id"/>
    > </xsl:variable>
    >
    > <td><xsl:value-of select="gyear"/></td>
    > <xsl:for-each
    >
    > select="NewDataSet/Table[inv_main_id=$Vinv_main_id]">
    > <td><xsl:value-of select="assoc_initial"/></TD>
    > </xsl:for-each
    > </xsl:for-each
    >
    > this is what the output should
    > be:
    >
    >
    > 2002 FBFRFC
    >
    >
    > however it did not displayed any problems but the output is only:
    >
    >
    > 2002
    >
    >
    > it seems it doesn't execute the second for-each loop.
    > Thanks in advance
     
    Pheckz, Jan 6, 2005
    #3
    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. John Blair
    Replies:
    1
    Views:
    426
    Eliyahu Goldin
    Aug 3, 2005
  2. Tjerk Wolterink

    xsl:for-each for each 3 elements problem

    Tjerk Wolterink, Nov 3, 2004, in forum: XML
    Replies:
    3
    Views:
    446
    Tjerk Wolterink
    Nov 3, 2004
  3. Pat Maddox
    Replies:
    6
    Views:
    162
    Marcin Mielżyński
    Jan 20, 2006
  4. Igor Nn
    Replies:
    7
    Views:
    455
    Johnny Morrice
    May 28, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    149
    PerlFAQ Server
    Jan 26, 2011
Loading...

Share This Page