-1

嗨,我有以下用于创建锚标签的 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

谢谢

4

1 回答 1

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>

添加一个新模板以使用当前 text() 调用命名的模板。

<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>
于 2013-04-29T13:28:24.370 回答