As part of my solution to the problem I posted a few weeks ago (
http://p2p.wrox.com/topic.asp?TOPIC_ID=22952) about compressing XML, I am condensing all the attribute values in a node into one long delimeted string.
e.g.
<node att1="23" att2="567" att3="7778" att4="999"/>
becomes
<node ats="23|567|7778|999|"/>
(if you have a large amount of attributes with long descriptive names then this does become worthwhile!)
Anyway, after the XML has been posted, I need to get it back into its original form. I need to be able to extract a particular value from the string.
I need to have a template which would insert the required value, in this case item 0 which has a value of 23
<xsl:attribute name="att1"><xsl:call-template name="Extractvalue"><xsl:with-param name="ItemNo" select="0"/><xsl:with-param name="Ats" select="@ats"/></xsl:call-template></xsl:attribute>
I've got this far, which does return the value of the first item
<xsl:template name="ExtractValue">
<xsl:param name="ItemNo"/>
<xsl:param name="Ats"/>
<xsl:variable name="Item" select="substring-before($Ats,'|')"/>
<xsl:value-of select="$Item"/>
</xsl:template>
I know that to get subsequent values I need to use a recursive template which accpets the remainder of the string and returns the first value, repeated x number of times till you get to the value that you want.
e.g. to get the thrid value
remove first value, pass in rest of string
remove second value, pass in rest of string
remove third value and return it
I just can't get my head around recursive templates enough to be able to do this! Any help will be appreciated.
Thanks