I had try Toby's solution, but still I only can get the result as /111. the recursion apply-template at least should return the last class_name, but why it still only catch the first one...
here is my code, with small modification on Toby's solution
<
xsl:template match="/">< data>
<xsl:apply-templates select="sql:rowset/sql:row/sql:rowset/sql:row " mode="class-string"/>
</data >
</xsl:template>
<xsl:template match="sql:row" mode
="class-string">
<xsl:if test="
sql:rowset">
<xsl:apply-templates select="sql:rowset/sql:row
" mode="class-string"/>
</xsl:if
>
<xsl:text>/</xsl:text
>
<xsl:value-of select="normalize-space( sql:class_name )
"/>
</xsl:template>
</xsl:stylesheet>
and the result is <data>/111</data>2006/7/18, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> I need some advice for writing a xsl for a nested sql result.
> the source file is
>
> <rowset>
> <row>
> <id>test</id>
> <rowset>
> <row>
> <class_name> 111</class_name>
> <rowset>
> <row>
> <class_name> 11</class_name>
> <rowset>
> <row>
> <class_name> 1</class_name>
> <rowset>
> <row>
> <class_name>0</class_name>
> </row>
> </rowset>
> </row>
> </rowset>
> </row>
> </rowset>
> </row>
> </rowset>
> </row>
> </rowset>
>
> I want the result as 0/1/11/111,
Ok, Toby was faster than me, and actually I like his solution better.
Nevertheless, here is a non-recursive solution to your problem. You can
insert the following snippet somewhere in your stylesheet, where a node
containing your outermost class_name element is the context node:
<xsl:for-each select="descendant::class_name">
<xsl:sort select="position()" order="descending"/>
<xsl:value-of select="normalize-space(.)"/>
<xsl:if test="position() != last()">
<xsl:text>/</xsl:text>
</xsl:if>
</xsl:for-each>
If you want to be more typesafe, use "descendant::rowset/row/class_name"
in the first select attribute instead.
Regards,
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
