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

Re: Coma delimited values in attribute

Subject: Re: Coma delimited values in attribute
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Sat, 17 Sep 2005 10:16:14 +0100
coma delimited
If you can use 2.0 (or 1.0 + extensions) then I would do it in 2
stages - the first stage sorts out the markup into a better structure.
 The second stage is really simple then.

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="betterMarkup">
	<xsl:for-each select="//field">
		<field>
			<xsl:for-each select="tokenize(@value, ',')">
				<value><xsl:value-of select="."/></value>
			</xsl:for-each>
		</field>
	</xsl:for-each>
</xsl:variable>

<xsl:template match="Fields">
	<table>
		<xsl:apply-templates select="$betterMarkup"/>
	</table>
</xsl:template>

<xsl:template match="field">
	<tr>
		<xsl:apply-templates/>
	</tr>
</xsl:template>

<xsl:template match="value">
	<td>
		<xsl:apply-templates/>
	</td>
</xsl:template>

</xsl:stylesheet>


Here the variable $betterMarkup reorganises the input into a better
structure:

<field>
	<value>tarif1</value>
	<value>tarif2</value>
	<value>tarif3</value>
	<value>tarif4</value>
</field>
<field>
	<value>str</value>
	<value>cur</value>
	<value>str</value>
	<value>cur</value>
</field>
<field>
	<value>1</value>
	<value>1</value>
	<value>1</value>
	<value>1</value>
</field>
<field>
	<value>152</value>
	<value>100</value>
	<value>252</value>
	<value>203</value>
</field>

The second stage then does an apply-templates on that structure.

If you wanted to do this in 1.0 you will need the node-set extension,
and optionally the tokenize extension (you could do it recursively)

cheers
andrew

Current Thread

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.