andrew welch wrote:
Hi
Using xsl:analyze-string, how would I add a count to the matching
items:
<xsl:analyze-string select="$string" regex=".{{1,6}}\^">
<xsl:matching-substring>
<line count="{ ?? }"><xsl:value-of select="."/></line>
</xsl:matching-substring>
<xsl:non-matching-substring>
<non><xsl:value-of select="."/></non>
</xsl:non-matching-substring>
</xsl:analyze-string>
...so that the output would be:
<line count="1">....
<line count="2">....
Is this possible or does it require two passes?
I'm not sure, but if I understood well, you need simply position():
~/xslt/tests> cat analyse-string.xsl
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:param name="input" select="'aa^aaa^aaa^^aa'"/>
<xsl:template name="main">
<xsl:analyze-string select="$input" regex=".{{1,6}}\^">
<xsl:matching-substring>
<line count="{ position() }">
<xsl:value-of select="."/>
</line>
</xsl:matching-substring>
<xsl:non-matching-substring>
<non>
<xsl:value-of select="."/>
</non>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:transform>
~/xslt/tests> saxon -it main analyse-string.xsl
<line count="1">aa^</line>
<line count="2">aaa^</line>
<line count="3">aaa^</line>
<non>^aa</non>
Regards,
--drkm
___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son
interface révolutionnaire.
http://fr.mail.yahoo.com
--~------------------------------------------------------------------
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>
--~--