Hi,
I am transforming the XML one to another format. I have an
instant in my
input xml tree like below
<cross-ref refid="bib2 bib4 bib5
bib6"><sup>2,4–6</sup></cross-ref>.
And, after the transformation I need result as below
<sup><a href="#bib2">2</a>, <a href="#bib4">4</a>, <a
href="#bib5">5</a>, <a href="#bib6">6</a></sup>
Please advise, hot to achieve this.
<xsl:template match="cross-ref">
<sup>
<xsl:call-template name="tokenizer">
<xsl:with-param name="refids" select="@refid"/>
<xsl:with-param name="text">
<xsl:call-template name="expand">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</sup>
</xsl:template>
<xsl:template name="tokenizer">
<xsl:param name="refids" select="''"/>
<xsl:param name="text" select="''"/>
<xsl:choose>
<xsl:when test="contains($refids, ' ')">
<a href="#{substring-before($refids, ' ')}">
<xsl:value-of select="substring-before($text, ',')"/>
</a>
<xsl:text>, </xsl:text>
<xsl:call-template name="tokenizer">
<xsl:with-param name="refids" select="substring-after($refids, ' ')"/>
<xsl:with-param name="text" select="substring-after($text, ',')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<a href="#{$refids}">
<xsl:value-of select="$text"/>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="expand">
<xsl:param name="text" select="''"/>
<xsl:choose>
<xsl:when test="contains($text, ',')">
<xsl:choose>
<xsl:when test="contains(substring-before($text, ','), '–')">
<xsl:call-template name="range">
<xsl:with-param name="start" select="substring-before($text,
'–')"/>
<xsl:with-param name="end"
select="substring-before(substring-after($text, '–'), ',')"/>
</xsl:call-template>
<xsl:text>,</xsl:text>
<xsl:call-template name="expand">
<xsl:with-param name="text" select="substring-after($text, ',')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($text, ',')"/>
<xsl:text>,</xsl:text>
<xsl:call-template name="expand">
<xsl:with-param name="text" select="substring-after($text, ',')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains($text, '–')">
<xsl:call-template name="range">
<xsl:with-param name="start" select="substring-before($text,
'–')"/>
<xsl:with-param name="end" select="substring-after($text,
'–')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="range">
<xsl:param name="start" select="0"/>
<xsl:param name="end" select="0"/>
<xsl:choose>
<xsl:when test="not($start = $end)">
<xsl:value-of select="$start"/>
<xsl:text>,</xsl:text>
<xsl:call-template name="range">
<xsl:with-param name="start" select="$start + 1"/>
<xsl:with-param name="end" select="$end"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$start"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Cheers,
Jarno - Suicide Commando: Face Of Death (Waking Up The Dancefloor Mix by
Implant)