Input:
<para>
<text>1. this a paragaraph1</text>
<text>12. this a paragaraph2</text>
<text>2. this a paragaraph2</text>
<text>this a paragaraph3</text>
</para>
My current output:
<result>
<para type="number">1. this a paragaraph1</para>
<para type="number">12. this a paragaraph2</para>
<para type="number">2. this a paragaraph2</para>
<para type="not number">this a paragaraph3</para>
</result>
Output should be:
<result>
<para type="number">1. this a paragaraph1</para>
<para type="number double">12. this a paragaraph2</para>
<para type="number">2. this a paragaraph2</para>
<para type="not number">this a paragaraph3</para>
</result>
Explanation of the logic:
You can see para/text has a string. Some of them are starting with numbers (1. , 12. ) then . and space. At that time para/@type must be number. If the count of that number is 1 @type should be number. If the count of that number is 2 @type should be number double. You can see the example.
Tried code:
<xsl:template match="text">
<xsl:choose>
<xsl:when test="matches(.,'^[0-9]+\. ')">
<para type="number">
<xsl:value-of select="."/>
</para>
</xsl:when>
<xsl:otherwise>
<para type="not number">
<xsl:value-of select="."/>
</para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="para">
<xsl:apply-templates/>
</xsl:template>
I am using XSLT 2.0.