Попробуйте следующим образом:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:param name="input"/>
<xsl:template match="/">
<Periods>
<xsl:call-template name="tokenize-to-pairs">
<xsl:with-param name="text" select="$input"/>
</xsl:call-template>
</Periods>
</xsl:template>
<xsl:template name="tokenize-to-pairs">
<xsl:param name="text"/>
<xsl:param name="delimiter" select="'|'"/>
<xsl:if test="contains($text, $delimiter) and contains(substring-after($text, $delimiter), $delimiter)">
<xsl:call-template name="parse-period">
<xsl:with-param name="month1" select="substring-before($text, $delimiter)"/>
<xsl:with-param name="month2" select="substring-before(substring-after($text, $delimiter), $delimiter)"/>
</xsl:call-template>
<!-- recursive call -->
<xsl:call-template name="tokenize-to-pairs">
<xsl:with-param name="text" select="substring-after(substring-after($text, $delimiter), $delimiter)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="parse-period">
<xsl:param name="month1"/>
<xsl:param name="month2"/>
<Period Year="{substring-before(substring-after($month1, ':'), ',')}">
<Months
month1="{substring-before($month1, ':')}"
month1Value="{substring-after($month1, ',')}"
month2="{substring-before($month2, ':')}"
month2Value="{substring-after($month2, ',')}"/>
</Period >
</xsl:template>
</xsl:stylesheet>
Когда эта таблица стилей вызывается с параметром input
:
Apr:2013,XXX/STD|Mar:2013,XXX/STD|Feb:2013,XXX/STD|Jan:2013,XXX/STD|Dec:2012,XXX/STD|Nov:2012,XXX/STD|Oct:2012,XXX/STD|Sep:2012,XXX/STD|Aug:2012,XXX/STD|Jul:2012,XXX/STD|Jun:2012,XXX/STD|May:2012,XXX/STD|Apr:2012,XXX/STD|Mar:2012,XXX/STD|
результат будет:
<Periods>
<Period Year="2013">
<Months month1="Apr" month1Value="XXX/STD" month2="Mar" month2Value="XXX/STD"/>
</Period>
<Period Year="2013">
<Months month1="Feb" month1Value="XXX/STD" month2="Jan" month2Value="XXX/STD"/>
</Period>
<Period Year="2012">
<Months month1="Dec" month1Value="XXX/STD" month2="Nov" month2Value="XXX/STD"/>
</Period>
<Period Year="2012">
<Months month1="Oct" month1Value="XXX/STD" month2="Sep" month2Value="XXX/STD"/>
</Period>
<Period Year="2012">
<Months month1="Aug" month1Value="XXX/STD" month2="Jul" month2Value="XXX/STD"/>
</Period>
<Period Year="2012">
<Months month1="Jun" month1Value="XXX/STD" month2="May" month2Value="XXX/STD"/>
</Period>
<Period Year="2012">
<Months month1="Apr" month1Value="XXX/STD" month2="Mar" month2Value="XXX/STD"/>
</Period>
</Periods>
Обратите внимание, что год периода - это год первого месяца.