String join problem

706 views
Skip to first unread message

Slawek

unread,
Apr 27, 2008, 7:05:25 AM4/27/08
to XSLT
Hello, I have a problem with strings and cannot figure it out. I
think it's pretty simple for someone experienced in XSLTs but I'm not
one of those.

The input to my XSLT is

<content>
....
<info>Some Text</info>
<info>Some More Text</info>
</content>

and my XSLT code snippet is

<xsl:variable name="sum_info">
<xsl:for-each select="/content/info">
<xsl:variable name="one_info"><xsl:value-of select="text()"/></
xsl:variable>
<xsl:value-of select="string-join(($sum_info,$one_info),'|')"/>
</xsl:for-each>
</xsl:variable>

As you can see what I'm trying to do is join all infos into 1 string
separated by "|".

Any help would be greatly appreciated.

Slawek

Balaji

unread,
Apr 28, 2008, 1:31:26 AM4/28/08
to XSLT
hi,

try this below code, but its xslt 1.0

<xsl:template match="root">
<xsl:for-each select="info">
<xsl:variable name="one_info"><xsl:value-of select="text()"/></
xsl:variable>
<xsl:value-of select="concat(concat('a',$one_info),'|')"/>
</xsl:for-each>
</xsl:template>

or

<xsl:template match="root">
<xsl:apply-templates/>
<xsl:text>|</xsl:text>
</xsl:template>

Regards,
Balaji. M

Slawek

unread,
Apr 28, 2008, 7:05:39 AM4/28/08
to XSLT
Hi Balaji,

Unless I'm missing something, the code you sent me concatenates the
info strings together but does not put the result in the same variable
as one of the concatenation parameters.

What I'm trying to do is:

string = string + another string

What I was thinking is if this simple operation is not possible in
XSLT then what I had to do is create a template, and do recursive
calls to it. But I'm hesitant to start doing this... ;-)

Thanks for your help,

Slawek

Balaji

unread,
Apr 28, 2008, 11:41:54 PM4/28/08
to XSLT
Hi,

Use call-template for recursive and the below sample code may be
fulfill your requirement.

Now one_info variable cotain

string = string + some other content

<xsl:template match="root">
<xsl:for-each select="info">
<xsl:variable name="one_info">
<xsl:call-template name="recursive">
<xsl:with-param name="value" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$one_info"/><br/>
</xsl:for-each>
</xsl:template>

<xsl:template name="recursive">
<xsl:param name="value" select="0"/>
<xsl:value-of select="concat(concat('a',$value),'|')"/>
</xsl:template>

Regards,
Balaji. M

> > > Slawek- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages