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

RE: String as Node

Subject: RE: String as Node
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Mon, 19 May 2003 14:43:59 -0400
string to node
[ Karl J. Stubsjoen]

> If an attribute contains a string, and that string's value is a space
> delimited value of numbers and I want to loop (verbiage?) 
> through each of
> those numbers like it was a node list (verbiage?), how could 
> I do this?
> 
> SO:
> 
> <myxml>
>     <anyelement anyatt="1 2 3 4 5 6 7 8 9 10"/>
> </myxml>
> 

You can either look up one of the tokenizer extensions, like the one
Dimitre has in his FXSL package - just look in the FAQs - or you can
write a simple recursive template yourself.  Here is an example.  You
will notice that there are a few tests for empty values of the
variables.  The test for $first is needed because substring-before will
return an empty string if there is no space in the string.  Of course
the tests can be arranged differently (you could use
choose..when..otherwise).

The point is to split off the first item and do something with it, then
call the template again the the remaining fragment.

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

<xsl:template match="/myxml">
<results>
	<xsl:call-template name='split'>
		<xsl:with-param name='data'
select='anyelement/@anyatt'/>
	</xsl:call-template>
</results>
</xsl:template>

<xsl:template name='split'>
	<xsl:param name='data'/>
	
	<xsl:variable name='first' select='substring-before($data,"
")'/>
	<xsl:variable name='rest' select='substring-after($data," ")'/>
	
	<xsl:if test='$first'><xsl:value-of
select='$first'/>...</xsl:if>
	<xsl:if test='$rest'>
		<xsl:call-template name='split'>
			<xsl:with-param name='data' select='$rest'/>
		</xsl:call-template>
	</xsl:if>
	<xsl:if test='not($rest)'><xsl:value-of
select='$data'/></xsl:if>

</xsl:template>
</xsl:stylesheet>

Cheers,

Tom P

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.