Reputation: 55
Anyone got XSL code that'll convert a string in (key=val) format (see example)
Keep getting errors, when I try to run it that I can't diagnose due to lack of knowledge with the language.
Given: fr=me to=you do=command Num=1521739
Desire (in XSL):
<command>
<Input>
<Num>1521739</Num>
</Input>
</command>
Upvotes: 0
Views: 32
Reputation: 116992
Well, given $string
containing:
fr=me to=you do=command Num=1521739
you can extract the value of do
as:
<xsl:value-of select="substring-before(substring-after($string, 'do='), ' ')"/>
and the value of Num
as:
<xsl:value-of select="substring-after($string, 'Num=')"/>
If you don't know the order of the pairs, append a space to the string before extracting a value:
<xsl:value-of select="substring-before(substring-after(concat($string, ' '), 'Num='), ' ')"/>
Similarly, if you suspect that a key can be contained in another key, e.g.
do=command undo=option
use a leading space to select the key unambiguously:
<xsl:value-of select="substring-before(substring-after(concat(' ', $string, ' '), ' do='), ' ')"/>
Upvotes: 1