Discussion:
Concat string in XSLT problem
(too old to reply)
BEN
2004-07-28 15:33:16 UTC
Permalink
Hi,

I want to concat all value of attributes into a value as output.

My XML is
<a>
<b id='1'/>
<b id='2'/>
<b id='3'/>
<b id='4'/>
</a>

The file output is still a XML file and the value of a tag I want is
'1,2,3,4' (concat all value of 'id')
<o>1,2,3,4</o>

I tried to use 'concat' function and variable in XSLT file but not success.
I only retrieve '4' as the output. Please help.

Thanks in advance.

Bennett
Han
2004-07-28 20:03:39 UTC
Permalink
concat() will do, but it has another limit. You should know the count of the
interested nodes exactly. for-each is simple. pseudo code,

<xsl:template match=a>
<o>
<xsl:for-each select=b>
<xsl:value-of select=@id/>
<xsl:if test=not(position()=last())>
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</o>
</xsl:template>
Post by BEN
Hi,
I want to concat all value of attributes into a value as output.
My XML is
<a>
<b id='1'/>
<b id='2'/>
<b id='3'/>
<b id='4'/>
</a>
The file output is still a XML file and the value of a tag I want is
'1,2,3,4' (concat all value of 'id')
<o>1,2,3,4</o>
I tried to use 'concat' function and variable in XSLT file but not success.
I only retrieve '4' as the output. Please help.
Thanks in advance.
Bennett
BEN
2004-07-29 11:59:10 UTC
Permalink
Thx Han. I solved the problem using current() and for-each
select='/a/b/@id'. Of course last() is used.

Bennett
Post by Han
concat() will do, but it has another limit. You should know the count of the
interested nodes exactly. for-each is simple. pseudo code,
<xsl:template match=a>
<o>
<xsl:for-each select=b>
<xsl:if test=not(position()=last())>
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</o>
</xsl:template>
Post by BEN
Hi,
I want to concat all value of attributes into a value as output.
My XML is
<a>
<b id='1'/>
<b id='2'/>
<b id='3'/>
<b id='4'/>
</a>
The file output is still a XML file and the value of a tag I want is
'1,2,3,4' (concat all value of 'id')
<o>1,2,3,4</o>
I tried to use 'concat' function and variable in XSLT file but not
success.
Post by BEN
I only retrieve '4' as the output. Please help.
Thanks in advance.
Bennett
Loading...