Selecting subelements from a node-set

T

thomas

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
 
D

Dimitre Novatchev

thomas said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top