SPLIT DATA IN VARIABLE

Here should go questions about transforming XML with XSLT and FOP.
Le Basque
Posts: 147
Joined: Sat Oct 19, 2013 8:21 am

SPLIT DATA IN VARIABLE

Post by Le Basque »

Hi,

I have data xml

Code: Select all

<x>1#2#3#4</x>
I would like to make a SPLIT on the # character and retrieve each value in variable named
For the following result :

Code: Select all


var1="1"
var2="2"
var3="3"
var4="4"
Can you help me ?

Thank you
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: SPLIT DATA IN VARIABLE

Post by adrian »

Hi,

You can use the tokenize XSLT 2.0 function:
http://www.w3schools.com/xpath/xpath_functions.asp
e.g.
tokenize('1#2#3#4', '#')
will give you the 4 tokens(1, 2, 3, 4).

Code: Select all

<xsl:template match="x">
<xsl:for-each select="tokenize(text(), '#')">
<xsl:variable name="token" select="."/>
</xsl:for-each>
</xsl:template>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Le Basque
Posts: 147
Joined: Sat Oct 19, 2013 8:21 am

Re: SPLIT DATA IN VARIABLE

Post by Le Basque »

i use xslt V1.0

I use a solution not terrible

Code: Select all


<xsl:variable name="var" select="xx"/>
<xsl:variable name="var1" select="substring-before($var, '#')"/>
<xsl:variable name="tmp" select="substring-after($var, '#')"/>
<xsl:variable name="var2" select="substring-before($tmp, '#')"/>
<xsl:variable name="tmp1" select="substring-after($tmp, '#')"/>
...
Post Reply