On Mon, 3 Nov 2003, Ravi wrote:
I am new to XSL. I have a XML document something like
<abc>
xyz
<def> 1 </def>
<def> 2 </def>
<def> 3 </def>
<def> 4 </def>
<def> 5 </def>
</abc>
I am trying to get the value of the abc node which in this case is xyz.
However if I try to get the value using <xsl:value-of select="."/> in a
template matching abc I get
xyz 1 2 3 4 5
which is not what I want. Is there someway to select only the value of
the parent node and then display each child node's value on say a
separate line? I tried using concat and substring-before and though it
works its not a good solution as I do not know how many children abc has
in advance (besides being very laborious). Any suggestions will be
highly appreciated.
To get all of the text values of all of the children of <abc> on
separate lines you can loop through all children:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:for-each select="*">
<xsl:value-of select="." />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
To get just the single text value of <abc> without the <def> children at
all you can use the text() function:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:value-of select="/abc/text()" />
</xsl:template>
</xsl:stylesheet>
--
Dino Morelli
di**********@snet.net .~.
http://www.debian.org Debian GNU/Linux /V\
/( )\
^^-^^