|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: String as 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








