Subject: Re: [xsl] Child Nodes Problem From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 03 Jun 2010 12:01:34 +0100 |
<xsl:variable name="delimiter" select="'	'"/> <xsl:variable name="fieldNames" select="'yes'"/>
<xsl:template match="/">
<xsl:for-each select="//Product/child::*|//Product/self::*">
this test is always true as position() is always an integer greater than zero, for all documents.
<xsl:if test="$fieldNames = 'yes'">
<xsl:if test="position() = 1 or position()>1">
this would list the names of the attributes (in an arbitrary order) but your sample input has no attributes
<xsl:for-each select="@*"> <xsl:value-of select="name()"/>
<xsl:value-of select="$delimiter"/>here you prpbably just want <xsl:text> </xsl:text>
</xsl:for-each>
<xsl:for-each select="*"> <xsl:value-of select="name()"/>
<xsl:if test="position() != last()"> <xsl:value-of select="$delimiter"/> </xsl:if> </xsl:for-each> <xsl:text> </xsl:text>
again this would list any attributes if you had them.</xsl:if> </xsl:if> <xsl:for-each select="@*"> <xsl:value-of select="."/> <xsl:value-of select="$delimiter"/> </xsl:for-each>
The above for-each (which was the xslt 1 way) can be more simply written as<xsl:for-each select="*"> <xsl:value-of select="."/> <xsl:if test="position() != last()"> <xsl:value-of select="$delimiter"/> </xsl:if> </xsl:for-each>
again just use ,xsl:text> </xsl:text> if you want to insert just a new line and no spaces.<xsl:text> </xsl:text>
David</xsl:for-each> </xsl:template>
________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Child Nodes Problem, Byomokesh Sahoo | Thread | Re: [xsl] Child Nodes Problem, Byomokesh Sahoo |
[xsl] Child Nodes Problem, Byomokesh Sahoo | Date | Re: [xsl] Child Nodes Problem, Byomokesh Sahoo |
Month |