I have the following xml pattern :
<tag name="(some_string)_start">
<tag name="step1">
<tag name="step2">
<tag name="step3">
<tag name="step4">
<tag name="(some_string)_end">
<tag name="(some_other_string)_start">
<tag name="step1">
<tag name="step2">
<tag name="step3">
<tag name="step4">
<tag name="step5">
<tag name="(some_other_string)_end">
I need to transform it to a text file as follows using XSLT:
name=(some_string), step_index=0
name=step1, step_index=1
name=step2, step_index=2
name=step3, step_index=3
name=step4, step_index=4
name=(some_string), step_index=5
name=(some_other_string), step_index=0
name=step1, step_index=1
name=step2, step_index=2
name=step3, step_index=3
name=step4, step_index=4
name=step5, step_index=5
name=(some_other_string), step_index=6
I want to count the number of nodes starting with suffix 'start' to 'end' When i encounter next name with suffix 'start', counter should be reinitialized to zero
Following is the XSLT I tried :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:accumulator name="step-index" initial-value="0">
<xsl:accumulator-rule match="sample[matches(@name, '.*Start$')]" select="0">
</xsl:accumulator-rule>
<xsl:accumulator-rule match="sample[matches(@name, '.*End$')]" select="$value+1">
</xsl:accumulator-rule>
</xsl:accumulator>
<xsl:template match="tag">
<xsl:text>,name=</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>,step-index=</xsl:text>
<xsl:value-of select="accumulator-after('step-index')"/>
</xsl:template>
</xsl:stylesheet>
But I dont get the desired output using the above accumulator method. How do I compute the step_index value using XSLT?
Thanks in advance!
xslt-2.0trying to use accumulators and telling "I don't get the desired output" begs the question whether you really have an XSLT 3 processor. Your code seems to lack<xsl:mode use-accumulators="#all"/>or<xsl:mode use-accumulators="step-index"/>for a start. - Martin Honnentagelements or sibling tag elements. - Martin Honnen