Selecting subelements from a node-set

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomas

    #1

    Selecting subelements from a node-set

    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>

    <thesubelemen t>
    <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="XAxsisNod eSet1" select="msxsl:n ode-set($test)"/>

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

    <xsl:for-each select="thesube lement/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







  • Dimitre Novatchev

    #2
    Re: Selecting subelements from a node-set


    "thomas" <th@dgr.dk> wrote in message
    news:401419c8$0 $154$edfadb0f@d read11.news.tel e.dk...[color=blue]
    > 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>
    >
    > <thesubelemen t>
    > <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="XAxsisNod eSet1" select="msxsl:n ode-set($test)"/>
    >
    > <xsl:for-each select="$XAxsis NodeSet1/theelement">
    > <xsl:value-of select="." /><br/>
    >
    > <xsl:for-each select="thesube lement/theelement2">
    > <xsl:value-of select="." /><br/>
    > </xsl:for-each>[/color]

    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 "thesubelem ent"
    children.

    If you want that a "theelement " element has a "thesubelem ent" child, then
    instead of:
    [color=blue]
    > <theelement>
    > <xsl:value-of select="'1'"></xsl:value-of>
    > </theelement>[/color]

    write:

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

    <thesubelemen t>
    <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


    Comment

    • thomas

      #3
      Re: Selecting subelements from a node-set

      Thanks for your help - that was a stupid mistake!


      "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
      news:bv19vk$n2r cd$1@ID-152440.news.uni-berlin.de...[color=blue]
      >
      > "thomas" <th@dgr.dk> wrote in message
      > news:401419c8$0 $154$edfadb0f@d read11.news.tel e.dk...[color=green]
      > > 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>
      > >
      > > <thesubelemen t>
      > > <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="XAxsisNod eSet1" select="msxsl:n ode-set($test)"/>
      > >
      > > <xsl:for-each select="$XAxsis NodeSet1/theelement">
      > > <xsl:value-of select="." /><br/>
      > >
      > > <xsl:for-each select="thesube lement/theelement2">
      > > <xsl:value-of select="." /><br/>
      > > </xsl:for-each>[/color]
      >
      > 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[/color]
      "thesubelem ent"[color=blue]
      > children.
      >
      > If you want that a "theelement " element has a "thesubelem ent" child, then
      > instead of:
      >[color=green]
      > > <theelement>
      > > <xsl:value-of select="'1'"></xsl:value-of>
      > > </theelement>[/color]
      >
      > write:
      >
      > <theelement>
      > <xsl:value-of select="'1'"></xsl:value-of>
      >
      > <thesubelemen t>
      > <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
      >
      >[/color]


      Comment

      Working...