Dear all, I am again trying to use xslt for thing which I reckon it is not designed for: it works very well so often that I insist in doing that...
I have now a latex file which has thousands of entries like this
Code:
\index[p]{pino!1!115.3}
which need to get (According to kinds) into this format
So I have used the following xsl
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template match="/">
<xsl:variable name="hdt">
<xsl:call-template name="hdt"/>
</xsl:variable>
<xsl:for-each select="$hdt">
<xsl:call-template name="plut"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="hdt">
<xsl:analyze-string select="." regex="([A-Za-z0-9]+)*(!)(\d)(!)((\d+)(\.)*(\d*)(\-*)(\d*)((\.)(\d*))*)(\|)*([A-Za-z0-9]+)*(\}})">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
<xsl:value-of select="regex-group(2)"/>
<xsl:value-of select="regex-group(3)"/>
<xsl:value-of select="regex-group(4)"/>
<xsl:value-of select="format-number(number(regex-group(6)), '0000')"/>
<xsl:choose>
<xsl:when test="regex-group(8)">
<xsl:value-of select="format-number(number(regex-group(8)), '0000')"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>0000</xsl:text>
</xsl:otherwise></xsl:choose>
<xsl:text>@</xsl:text>
<xsl:value-of select="regex-group(5)"/>
<xsl:value-of select="regex-group(14)"/>
<xsl:value-of select="regex-group(15)"/>
<xsl:value-of select="regex-group(16)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<xsl:template name="plut">
<xsl:analyze-string select="." regex="([A-Za-z0-9]+)*(!)(\\*)([A-Za-z0-9]+)*(\{{)*([A-Za-z0-9]+)*(\}})*((!)((\d+)(\.)*(\d*)(\-*)(\d*)((\.)(\d*))*)(\|)*([A-Za-z0-9]+)*)*(\}})">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
<xsl:value-of select="regex-group(2)"/>
<xsl:value-of select="regex-group(3)"/>
<xsl:value-of select="regex-group(4)"/>
<xsl:value-of select="regex-group(5)"/>
<xsl:value-of select="regex-group(6)"/>
<xsl:value-of select="regex-group(7)"/>
<xsl:value-of select="regex-group(9)"/>
<xsl:value-of select="format-number(number(regex-group(10)), '0000')"/>
<xsl:choose>
<xsl:when test="regex-group(12)">
<xsl:value-of select="format-number(number(regex-group(12)), '0000')"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>0000</xsl:text>
</xsl:otherwise></xsl:choose>
<xsl:text>@</xsl:text>
<xsl:value-of select="regex-group(10)"/>
<xsl:value-of select="regex-group(19)"/>
<xsl:value-of select="regex-group(20)"/>
<xsl:value-of select="regex-group(21)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
This works very well on a small file with only a selection of all things I want to match, which I have used to test. It does not work when I try to run it on a larger file. Please, do you have any suggestion on why this happens? Thank you very much
Pietro