Hi Harry,
Run the following example on itself and you will get the output you
desire. If you have trouble adopting it for your needs, please tell so.
Note that you may want to test for empty strings, when tokenizing
results in such (the output of below will include two empty results, one
for the first newline and one for the closing newline). You can do so by
adding the following statement to the appropriate places:
normalize-space(substring-after($string, '
')) != ''
Cheers,
-- Abel
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:variable name="input">
fw_rule3
fw_rule1
fw_rule2
</xsl:variable>
<xsl:template match="/">
<xsl:call-template name="stringtok">
<xsl:with-param name="string" select="$input"/>
<xsl:with-param name="pos" select="0" />
</xsl:call-template>
</xsl:template>
<xsl:template name="stringtok">
<xsl:param name="string" />
<xsl:param name="pos" />
<rule name="{normalize-space(substring-before($string,
'
'))}" precedence="{$pos}" />
<xsl:if test="contains($string, '
')">
<xsl:call-template name="stringtok">
<xsl:with-param name="string"
select="substring-after($string, '
')"/>
<xsl:with-param name="pos" select="$pos + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Harry Liljeström wrote:
Hi,
I have following input:
<fw-rule-order>
fw_rule3
fw_rule1
fw_rule2
</fw-rule-order>
and the desired output:
<rule name="fw_rule3" precedence="0"/>
<rule name="fw_rule1" precedence="1"/>
<rule name="fw_rule2" precedence="2"/>
Could someone give me any hints how this could be solved in XSLT 1.0?
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--