Selecting subelements from a node-set

Discussion in 'XML' started by thomas, Jan 25, 2004.

  1. thomas

    thomas Guest

    Hello all

    Im having problems with selecting subelements from a dynamic created RTF
    converted to a node-set:

    i have hardcodet this example:

    the xml structure:

    <xsl:variable name="test">
    <theelement>
    <xsl:value-of select="'1'"></xsl:value-of>
    </theelement>

    <thesubelement>
    <theelement2>
    <xsl:value-of select="'1-1'"></xsl:value-of>
    </theelement2>
    <theelement2>
    <xsl:value-of select="'1-2'"></xsl:value-of>
    </theelement2>
    </thesubelement>

    <theelement>
    <xsl:value-of select="'2'"></xsl:value-of>
    </theelement>
    <theelement>
    <xsl:value-of select="'3'"></xsl:value-of>
    </theelement>
    </xsl:variable>


    <xsl:variable name="XAxsisNodeSet1" select="msxsl:node-set($test)"/>

    <xsl:for-each select="$XAxsisNodeSet1/theelement">
    <xsl:value-of select="." /><br/>

    <xsl:for-each select="thesubelement/theelement2">
    <xsl:value-of select="." /><br/>
    </xsl:for-each>

    </xsl:for-each>

    i would expect the result to be:
    1
    1-1
    1-2
    2
    3

    but my result is
    1
    2
    3

    I never interates the subelements ??? does anyone know why?? i have
    tried different ways of doint this but no success?

    Please help

    Thomas
    thomas, Jan 25, 2004
    #1
    1. Advertising

  2. "thomas" <> wrote in message
    news:401419c8$0$154$...
    > Hello all
    >
    > Im having problems with selecting subelements from a dynamic created RTF
    > converted to a node-set:
    >
    > i have hardcodet this example:
    >
    > the xml structure:
    >
    > <xsl:variable name="test">
    > <theelement>
    > <xsl:value-of select="'1'"></xsl:value-of>
    > </theelement>
    >
    > <thesubelement>
    > <theelement2>
    > <xsl:value-of select="'1-1'"></xsl:value-of>
    > </theelement2>
    > <theelement2>
    > <xsl:value-of select="'1-2'"></xsl:value-of>
    > </theelement2>
    > </thesubelement>
    >
    > <theelement>
    > <xsl:value-of select="'2'"></xsl:value-of>
    > </theelement>
    > <theelement>
    > <xsl:value-of select="'3'"></xsl:value-of>
    > </theelement>
    > </xsl:variable>
    >
    >
    > <xsl:variable name="XAxsisNodeSet1" select="msxsl:node-set($test)"/>
    >
    > <xsl:for-each select="$XAxsisNodeSet1/theelement">
    > <xsl:value-of select="." /><br/>
    >
    > <xsl:for-each select="thesubelement/theelement2">
    > <xsl:value-of select="." /><br/>
    > </xsl:for-each>


    This last xsl:for-each instruction will not process any elements, as the
    XPath expression:

    thesubelement/theelement2

    will not select any node.

    The reason is that the "theelement" elements do not have any "thesubelement"
    children.

    If you want that a "theelement" element has a "thesubelement" child, then
    instead of:

    > <theelement>
    > <xsl:value-of select="'1'"></xsl:value-of>
    > </theelement>


    write:

    <theelement>
    <xsl:value-of select="'1'"></xsl:value-of>

    <thesubelement>
    <theelement2>
    <xsl:value-of select="'1-1'"></xsl:value-of>
    </theelement2>
    <theelement2>
    <xsl:value-of select="'1-2'"></xsl:value-of>
    </theelement2>
    </thesubelement>
    </theelement>


    Cheers,

    Dimitre Novatchev.
    FXSL developer, XML Insider,

    http://fxsl.sourceforge.net/ -- the home of FXSL
    Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
    Dimitre Novatchev, Jan 25, 2004
    #2
    1. Advertising

  3. thomas

    thomas Guest

    Thanks for your help - that was a stupid mistake!


    "Dimitre Novatchev" <> wrote in message
    news:bv19vk$n2rcd$-berlin.de...
    >
    > "thomas" <> wrote in message
    > news:401419c8$0$154$...
    > > Hello all
    > >
    > > Im having problems with selecting subelements from a dynamic created RTF
    > > converted to a node-set:
    > >
    > > i have hardcodet this example:
    > >
    > > the xml structure:
    > >
    > > <xsl:variable name="test">
    > > <theelement>
    > > <xsl:value-of select="'1'"></xsl:value-of>
    > > </theelement>
    > >
    > > <thesubelement>
    > > <theelement2>
    > > <xsl:value-of select="'1-1'"></xsl:value-of>
    > > </theelement2>
    > > <theelement2>
    > > <xsl:value-of select="'1-2'"></xsl:value-of>
    > > </theelement2>
    > > </thesubelement>
    > >
    > > <theelement>
    > > <xsl:value-of select="'2'"></xsl:value-of>
    > > </theelement>
    > > <theelement>
    > > <xsl:value-of select="'3'"></xsl:value-of>
    > > </theelement>
    > > </xsl:variable>
    > >
    > >
    > > <xsl:variable name="XAxsisNodeSet1" select="msxsl:node-set($test)"/>
    > >
    > > <xsl:for-each select="$XAxsisNodeSet1/theelement">
    > > <xsl:value-of select="." /><br/>
    > >
    > > <xsl:for-each select="thesubelement/theelement2">
    > > <xsl:value-of select="." /><br/>
    > > </xsl:for-each>

    >
    > This last xsl:for-each instruction will not process any elements, as the
    > XPath expression:
    >
    > thesubelement/theelement2
    >
    > will not select any node.
    >
    > The reason is that the "theelement" elements do not have any

    "thesubelement"
    > children.
    >
    > If you want that a "theelement" element has a "thesubelement" child, then
    > instead of:
    >
    > > <theelement>
    > > <xsl:value-of select="'1'"></xsl:value-of>
    > > </theelement>

    >
    > write:
    >
    > <theelement>
    > <xsl:value-of select="'1'"></xsl:value-of>
    >
    > <thesubelement>
    > <theelement2>
    > <xsl:value-of select="'1-1'"></xsl:value-of>
    > </theelement2>
    > <theelement2>
    > <xsl:value-of select="'1-2'"></xsl:value-of>
    > </theelement2>
    > </thesubelement>
    > </theelement>
    >
    >
    > Cheers,
    >
    > Dimitre Novatchev.
    > FXSL developer, XML Insider,
    >
    > http://fxsl.sourceforge.net/ -- the home of FXSL
    > Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
    >
    >
    thomas, Jan 25, 2004
    #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. Nitin Khurana
    Replies:
    2
    Views:
    822
    Jonathan Bromley
    Apr 27, 2004
  2. Replies:
    0
    Views:
    1,411
  3. Daniel Jorge

    SubElements in my WebControl

    Daniel Jorge, Jul 10, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    343
    Daniel Jorge
    Jul 10, 2005
  4. Nicole Szymanski
    Replies:
    3
    Views:
    798
  5. Tjerk Wolterink
    Replies:
    2
    Views:
    1,403
    Dimitre Novatchev
    Aug 24, 2006
Loading...

Share This Page