I've the below 4 cases in XML. I need a template match with regex tht can solve my below problem.
HTML Code:
<toc>
<secondaryie>Practice Direction, PD1.1/1âPD1.1/9</secondaryie>
<secondaryie>preliminary act</secondaryie>
<secondaryie>collision actions, 75/20</secondaryie>
<secondaryie>failure to lodge, E75/19/32</secondaryie>
</toc>
And the output i'm expecting is as below.
HTML Code:
<div class="secondaryie">Practice Direction,<a href="sec_1_PD1-1/1">PD1.1/1</a>â<a href="sec_1_PD1-1/9">PD1.1/9</a><div>
<div class="secondaryie">preliminary act<div>
<div class="secondaryie">collision actions,<a href="sec_1_P75/20">75/20</a><div>
<div class="secondaryie">failure to lodge,<span class="invalid">E75/19/32</span><div>
here for the last case the hint is, if the number is preceded any character apart from PD, it should create an invalid tag. Please let me know how i can do this.
Tried XSLT is as below
HTML Code:
<xsl:template match="secondaryie">
<div class="secondaryie">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="text()">
<xsl:analyze-string select="." regex="[\d/]+">
<xsl:matching-substring>
<xsl:variable name="range" select="tokenize(.,'â')"/>
<xsl:variable name="pg" select="tokenize(.,'/')"/>
<xsl:choose>
<xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ',substring(.,1,1)))">
<xsl:choose>
<xsl:when test="contains($pg[3],'â')">
<xsl:variable name="range-pg" as="item()*">
<xsl:for-each select="$range">
<xsl:sequence select="tokenize(.,'/')"/>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="xs:integer($range-pg[3]) to xs:integer($range-pg[6])">
<a href="er:#HKWBV1_ORD_{
if (string(number($range-pg[1]))!='NaN') then
format-number(number($range-pg[1]),'00')
else
$range-pg[1]}/P{string-join($range-pg[position()=(1,2)],'/')}/{.}">
<xsl:value-of select="concat(string-join($range-pg[position()=(1,2)],'/'),'/',.)"/>
</a>
<xsl:text>, </xsl:text>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<a href="er:#HKWBV1_ORD_{
if (string(number($pg[1]))!='NaN') then
format-number(number($pg[1]),'00')
else
$pg[1]}/P{$pg[1]
}/{string-join($pg[position()>1],'/')}">
<xsl:value-of select="."/>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains('PD',substring(.,1,2))">
<a href="{concat('HKWBV1_SEC_',substring-after(substring-before(.,'/'),'PD'),'/PPD',translate(substring-after(.,'PD'),'.','-'))}">
<xsl:value-of select="."/>
</a>
</xsl:when>
<xsl:otherwise>
<span class="invalid">
<xsl:value-of select="."/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
Thanks