This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: concat string
- To: <xsl-list at mulberrytech dot com>
- Subject: RE: concat string
- From: "Jon Payne" <Jon dot Payne at ttpcom dot com>
- Date: Thu, 30 Nov 2000 17:07:34 -0000
- Reply-To: xsl-list at mulberrytech dot com
Hi YueMa,
I'm an XSLT newbie myself, but I think these should work.
Below are two slightly different ways of achieving the output:
> <META http-equiv="Keywords" name="Keywords" content="key1,
> key2, key3">
from your source:
> ..
> <keys>key1</keys>
> <keys>key2</keys>
> <keys>key3</keys>
> ..
'method1' uses a template to match on 'keys' and uses xsl:attribute .
'method2' uses xsl:for-each and xsl:variable.
Note: both methods match on ALL 'keys' which may not be what you want.
Regards,
Jon.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:call-template name="method1"/>
<xsl:call-template name="method2"/>
</xsl:template>
<xsl:template name="method2">
<xsl:variable name="keys">
<xsl:for-each select="//keys">
<xsl:value-of select="."/>
<xsl:call-template name="comma"/>
</xsl:for-each>
</xsl:variable>
<META http-equiv="Keywords" name="Keywords" content="{$keys}"/>
</xsl:template>
<xsl:template name="method1">
<xsl:element name="META">
<xsl:attribute name="http-equiv">Keywords</xsl:attribute>
<xsl:attribute name="name">Keywords</xsl:attribute>
<xsl:attribute name="content">
<xsl:apply-templates mode="keys"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
<xsl:template match="keys" mode="keys">
<xsl:value-of select="."/>
<xsl:call-template name="comma"/>
</xsl:template>
<xsl:template name="comma">
<xsl:if test="name(following-sibling::node()) = name(self::node())">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
>
> How can I do that ?
>
> Thanks!
>
>
>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list