[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: concat string

Subject: RE: concat string
From: "Jon Payne" <Jon.Payne@xxxxxxxxxx>
Date: Thu, 30 Nov 2000 17:07:34 -0000
xsl attribute concat
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


Current Thread
  • concat string
    • YueMa - Thu, 30 Nov 2000 10:06:49 -0500
      • Jon Payne - Thu, 30 Nov 2000 17:07:34 -0000 <=
      • Ian Davis - Thu, 30 Nov 2000 17:53:06 +0000

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.