I need to turn the values in a xml attribute through xsl into a svg rect pos x and y
Therefore need to parse from
Examples
<item value="20 10 40" />
<item value="200 0 100" />
<item value="2666 10 40 95" />
parse each item value attribute following some rules (that's the part I'm not sure about, how to extract the numbers into separate variables)
like
<item value="20 10 40" />
X Z Y
Extract X (20) in var1 and Y (40) in var2
into
<rect x="{$var1}" y="{$var2}" />
(if I want the first and third value in this case)
Basically I need to understand how to parse any TWO of a series of multiple values contained within the attribute VALUE and pass them into the rect vars as var1 and var2 separately.
From my research so far, I have found out 2 methods but not sure how to apply in this case, either substring-before and after or tokenize, please note this needs to work loaded directly in a browser.
Edit1
I have found an ugly solution so far to extract the data for a case of 3 numbers
Xml
<item value="20 10 40" />
Xsl
Value 1 <xsl:value-of select="substring-before (@value, ' ')"/>
Value 2 <xsl:value-of select="substring-before(substring-after (@value, ' '), ' ')"/>
Value 3 <xsl:value-of select="substring-after(substring-after (@value, ' '), ' ')"/>
Result
Value 1 20
Value 2 10
Value 3 40
So looking for something cleaner, perhaps recursive that accept any amount of numbers in the string and parse all.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…