您好我在下面的xslt用于创建锚标签。
<xsl:template match="para/text()">
<xsl:variable name="numx">
<xsl:number format="1" level="any"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="(contains(substring(substring-after(current(),'.'),4,1),')') or contains(substring(substring-after(current(),'.'),4,1),'.') or contains(substring(substring-after(current(),'.'),4,1),' ')) and (contains(substring (current(),string-length(substring-before(current(), '.')) -1,2),' ')) and contains(substring(current(),string-length(substring-before(current(), '.')) -2,1),$numx)">
<xsl:variable name="before">
<xsl:value-of select="normalize-space(substring(current(),string-length(substring-before(current(), '.')) -1,2))"/>
</xsl:variable>
<xsl:variable name="NewN">
<xsl:value-of select="concat('0',$before)"/>
</xsl:variable>
<xsl:variable name="after">
<xsl:value-of select="substring(substring-after(current(),'.'),1,3)"/>
</xsl:variable>
<xsl:variable name="befdNumb">
<xsl:value-of select="substring-before(current(),$before)"/>
</xsl:variable>
<xsl:variable name="aftdNumb">
<xsl:value-of select="substring-after(current(),$after)"></xsl:value-of>
</xsl:variable>
<xsl:value-of select="$befdNumb"/>
<xsl:text> </xsl:text>
<a href="{concat('er:#CLI_CH_',$NewN,'/','P',normalize-space($before),'-',$after)}">
<xsl:value-of select="concat(normalize-space($before),'.',$after)"/>
</a>
<xsl:value-of select="$aftdNumb"/>
</xsl:when>
<xsl:when test="(contains(substring(substring-after(current(),'.'),4,1),')') or contains(substring(substring-after(current(),'.'),4,1),'.') or contains(substring(substring-after(current(),'.'),4,1),' ')) and contains(substring (current(),string-length(substring-before(current(), '.')) -2,1),' ')">
<xsl:variable name="before">
<xsl:value-of select="substring(current(),string-length(substring-before(current(), '.')) -2,3)"/>
</xsl:variable>
<xsl:variable name="NewN">
<xsl:value-of select="$before"/>
</xsl:variable>
<xsl:variable name="after">
<xsl:value-of select="substring(substring-after(current(),'.'),1,3)"/>
</xsl:variable>
<xsl:variable name="befdNumb">
<xsl:value-of select="substring-before(current(),$before)"/>
</xsl:variable>
<xsl:variable name="aftdNumb">
<xsl:value-of select="substring-after(current(),$after)"></xsl:value-of>
</xsl:variable>
<xsl:value-of select="$befdNumb"/>
<xsl:text> </xsl:text>
<a href="{concat('er:#CLI_CH_',$NewN,'/','P',normalize-space($before),'-',$after)}">
<xsl:value-of select="concat(normalize-space($before),'.',$after)"/>
</a>
<xsl:value-of select="$aftdNumb"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
但是这个xslt正在应用,即如果文本如下所示,则会创建锚标记。(在整个文本中只有'。')。
通过以下第12.012段讨论的方式之一向公司提供债权人签署的要求
但我希望它也适用于以下文字
<para>the major issues here concern the notion of principal and ancillary jurisdictions, the ideal being that the ancillary jurisdiction will defer to the principal jurisdiction on most important matters, with a view to bringing about a just, practical and economically rational winding-up of affairs. A relatively recent development in connection with that ideal concerns the judicial promotion of court-endorsed agreements known as "crossborder protocols" between liquidators and similar officers appointed in different jurisdictions. It is important in this context, however, not to lose sight of the fact that certain matters of "administration" always remain governed by Hong Kong law. See paragraphs 12.016 to 12.032 below.</para>
请让我知道我该怎么做。我需要将此数字转换为er:#CLI_CH_12 / P12-016和er:#CLI_CH_12 / P12-032
由于
答案 0 :(得分:1)
我很确定这可能有更好的方法,但是因为我不清楚这个xslt应该做什么,所以我会坚持你的解决方案。
您需要进行一些递归模板调用。 将当前的“para / text()”模板更改为以文本作为参数的命名模板。 但是用$ text
替换每个current()<xsl:template name="mytext">
<xsl:param name="text" />
<xsl:variable name="numx">
<xsl:number format="1" level="any"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="(contains(substring(substring-after($text,'.'),4,1),')')
or contains(substring(substring-after($text,'.'),4,1),'.')
or contains(substring(substring-after($text,'.'),4,1),' '))
and (contains(substring ($text,string-length(substring-before($text, '.')) -1,2),' '))
and contains(substring($text,string-length(substring-before($text, '.')) -2,1),$numx)">
<强> .... 强>
</xsl:template>
添加一个新模板,使用当前文本()调用指定的模板。
<xsl:template match="para/text()">
<xsl:call-template name="mytext" >
<xsl:with-param name="text" select="." />
</xsl:call-template>
</xsl:template>
在when
之前添加otherwise
,以便在未处理的点之前输出文本,并使用此点后面的文本调用命名模板。
<xsl:when test="contains(substring-after($text,'.'),'.')">
<xsl:value-of select="substring-before($text,'.')"/>
<xsl:text>.</xsl:text>
<xsl:call-template name="mytext">
<xsl:with-param name="text" select="substring-after($text,'.')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>