Subject: RE: [xsl] String as Node From: "Passin, Tom" <tpassin@xxxxxxxxxxxx> Date: Mon, 19 May 2003 14:43:59 -0400 |
[ 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] String as Node, Karl J. Stubsjoen | Thread | [xsl] Xsltproc document(), Andrew Kirkpatrick |
Re: [xsl] How to render a Ms Word D, J.Pietschmann | Date | RE: [xsl] Xsltproc document(), Passin, Tom |
Month |