DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: XSL and XML problem

  1. #1
    Svenne Guest

    XSL and XML problem


    lets say I have the following XML database design:

    <root>
    <test>
    <name>monkey</name>
    <test2>a</test2>
    <test2>a</test2>
    <test2>a</test2>
    <test2>a</test2>
    </test>
    <test>
    <name>eel</name>
    <test2>a</test2>
    <test2>a</test2>
    </test>
    </root>

    how would I do in XSL to output all test2 tags no matter how many there are?

    should this design be better?

    <root>
    <test>
    <name>monkey</name>
    <test2>
    <test3>a</test3>
    <test3>a</test3>
    <test3>a</test3>
    </test2>

    </test>
    <test>
    <name>monkey</name>
    <test2>
    <test3>a</test3>
    <test3>a</test3>
    <test3>a</test3>
    <test3>a</test3>
    <test3>a</test3>
    </test2>

    </test>
    </root>

    how should I do to output all test 3 tags? no matter how many they are?

    I have tried to put one for-each loop in another for-each loop but that only
    outputs one of the test3 tags, not all of them

    <xsl:for-each select="root/test">
    <xsl:value-of select="name"/>
    <xsl:for-each select="root/test2">
    <xsl:value-of select="test3"/>
    </xsl:for-each>
    </xsl:for-each>

    I'd appreciate an answer
    thanks alot!

  2. #2
    AC Guest

    Re: XSL and XML problem


    What about using <xsl:for-each select="//test2"> or <xsl:for-each select="//test3">?

    AC

    "Svenne" <matrx@home.se> wrote:
    >
    >lets say I have the following XML database design:
    >
    ><root>
    > <test>
    > <name>monkey</name>
    > <test2>a</test2>
    > <test2>a</test2>
    > <test2>a</test2>
    > <test2>a</test2>
    > </test>
    > <test>
    > <name>eel</name>
    > <test2>a</test2>
    > <test2>a</test2>
    > </test>
    ></root>
    >
    >how would I do in XSL to output all test2 tags no matter how many there

    are?
    >
    >should this design be better?
    >
    ><root>
    > <test>
    > <name>monkey</name>
    > <test2>
    > <test3>a</test3>
    > <test3>a</test3>
    > <test3>a</test3>
    > </test2>
    >
    > </test>
    > <test>
    > <name>monkey</name>
    > <test2>
    > <test3>a</test3>
    > <test3>a</test3>
    > <test3>a</test3>
    > <test3>a</test3>
    > <test3>a</test3>
    > </test2>
    >
    > </test>
    ></root>
    >
    >how should I do to output all test 3 tags? no matter how many they are?
    >
    >I have tried to put one for-each loop in another for-each loop but that

    only
    >outputs one of the test3 tags, not all of them
    >
    ><xsl:for-each select="root/test">
    > <xsl:value-of select="name"/>
    > <xsl:for-each select="root/test2">
    > <xsl:value-of select="test3"/>
    > </xsl:for-each>
    ></xsl:for-each>
    >
    >I'd appreciate an answer
    >thanks alot!



  3. #3
    Jack Guest

    Re: XSL and XML problem


    Try the following.
    <xsl:template match="test">
    <xsl:apply-templates select="test2" />
    </xsl:template>
    <xsl:template match="test2">
    <xsl:value-of select="."/>
    </xsl:template>


    "AC" <ac7117@eudoramail.com> wrote:
    >
    >What about using <xsl:for-each select="//test2"> or <xsl:for-each select="//test3">?
    >
    >AC
    >
    >"Svenne" <matrx@home.se> wrote:
    >>
    >>lets say I have the following XML database design:
    >>
    >><root>
    >> <test>
    >> <name>monkey</name>
    >> <test2>a</test2>
    >> <test2>a</test2>
    >> <test2>a</test2>
    >> <test2>a</test2>
    >> </test>
    >> <test>
    >> <name>eel</name>
    >> <test2>a</test2>
    >> <test2>a</test2>
    >> </test>
    >></root>
    >>
    >>how would I do in XSL to output all test2 tags no matter how many there

    >are?
    >>
    >>should this design be better?
    >>
    >><root>
    >> <test>
    >> <name>monkey</name>
    >> <test2>
    >> <test3>a</test3>
    >> <test3>a</test3>
    >> <test3>a</test3>
    >> </test2>
    >>
    >> </test>
    >> <test>
    >> <name>monkey</name>
    >> <test2>
    >> <test3>a</test3>
    >> <test3>a</test3>
    >> <test3>a</test3>
    >> <test3>a</test3>
    >> <test3>a</test3>
    >> </test2>
    >>
    >> </test>
    >></root>
    >>
    >>how should I do to output all test 3 tags? no matter how many they are?
    >>
    >>I have tried to put one for-each loop in another for-each loop but that

    >only
    >>outputs one of the test3 tags, not all of them
    >>
    >><xsl:for-each select="root/test">
    >> <xsl:value-of select="name"/>
    >> <xsl:for-each select="root/test2">
    >> <xsl:value-of select="test3"/>
    >> </xsl:for-each>
    >></xsl:for-each>
    >>
    >>I'd appreciate an answer
    >>thanks alot!

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center