我提供了以下XML数据。
<para><content-style font-style="bold">1/4 4.—</content-style>(1) In these Rules, unless the context otherwise requires, the following expressions have the meanings hereby respectively assigned to them, namely:
<orderedlist type="manual">
<item><para>“attend” includes the appearance by any person using electronic, mechanical or other means permitted by the Court;</para></item>
<item><para>“bailiff” includes the registrar, any clerk or other officer of the Court charged with the duties of a bailiff in the Subordinate Courts;</para></item>
<item><para>“Civil Procedure Convention” means the conventions set out in Appendix C to these Rules and includes any convention, treaty or agreement of any description or any provision thereof between different States relating to civil procedure in the court;</para></item>
<item><para>“folio” means 100 words, each figure being counted as one word;</para></item>
<item><para>“Form” means a form set out in Appendix A to these Rules, and a form so numbered in the Appendix;</para></item>
<item><para>“Judge” means a judge of the High Court or District Judge and includes, in cases where he is empowered to act, a Magistrate or the Registrar, as the case may require;</para></item>
<item><para>“officer” means an officer of the Supreme Court or Subordinate Courts;</para></item>
<item><para>“originating process” means a writ of summons or an originating summons;</para></item>
<item><para>“originating summons” means every summons for the commencement of proceedings other than a writ of summons;</para></item>
<item><para>“pleading” does not include an originating summons or preliminary act;</para></item>
<item><para>“receiver” includes a manager or consignee;</para></item>
<item><para>“Registry” means the Registry of the Supreme Court or the Registry of the Subordinate Courts, as the case may be, and references to the Registrar shall be construed accordingly;</para></item>
<item><para>“scheduled territories” has the meaning assigned to it by the Exchange Control Act (Chapter 99);</para></item>
<item><para>“Sheriff” includes a bailiff of the Subordinate Courts;</para></item>
<item><para>“sign”, in relation to the signing of documents by the Registrar, includes the affixing of a facsimile signature;</para></item>
<item><para>“solicitor” has the same meaning as in the Legal Profession Act (Chapter 161);</para></item>
<item><para>“summons” means every summons in a pending cause or matter.</para></item>
<item><para>“working day” means any day other than a Saturday, Sunday or public holiday;</para></item>
<item><para>“writ” means a writ of summons.</para></item>
</orderedlist></para>
这里有一个para
和orderedlist
,当我运行我的模板时,有序列表进入了段落,即orderedlist
内容已进入para
并且在orderedlist
模板被调用之后,我很困惑为什么会发生这种情况。
这是DEMO,请告诉我如何解决这个问题。
由于
答案 0 :(得分:1)
您尚未向我们展示您想要的结果,但根据您的匹配模式,您看起来好像当前需要在content-style
上应用模板,但您的call-template
会处理{{1}的字符串值元素。
因此我更改了代码如下:
para
导致http://xsltransform.net/eiZQaEP/1输出
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template name="para" match="para">
<xsl:apply-templates select="./node()[1][self::page]" mode="first"/>
<div>
<xsl:choose>
<xsl:when test="./@align">
<xsl:attribute name="class">
<xsl:text>para align-</xsl:text>
<xsl:value-of select="./@align"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="class">
<xsl:text>para</xsl:text>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="contains(./content-style[1],'/')">
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<xsl:template match="text()">
<xsl:analyze-string select="." regex="(([Cc]hapter)\s(\d+))">
<xsl:matching-substring>
<xsl:value-of select="."/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="http://[^ ]+">
<xsl:matching-substring>
<a href="{.}">
<xsl:value-of select="."/>
</a>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<xsl:template match="para/content-style[1]">
<xsl:analyze-string select="." regex="([0-9]+)/([0-9]+)/([0-9]+)">
<xsl:matching-substring>
<span class="phrase">
<a name="{concat('P',regex-group(1),'-',regex-group(2),'-',regex-group(3))}"/>
<xsl:value-of select="."></xsl:value-of>
</span>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="([0-9]+)/([0-9]+)">
<xsl:matching-substring>
<span class="phrase">
<a name="{concat('P',regex-group(1),'-',regex-group(2))}"/>
<xsl:value-of select="."></xsl:value-of>
</span>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."></xsl:value-of>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<xsl:template name="orderedlist" match="orderedlist">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template match="item">
<!--<xsl:apply-templates select="./para[1]/node()[1][self::page]" mode="first"/>-->
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="item/para">
<li class="item">
<xsl:variable name="strl">
<xsl:value-of select="string-length(../@num)"/>
</xsl:variable>
<xsl:for-each select=".">
<xsl:apply-templates select="./node()[1][self::page]" mode="first"/>
<div class="para">
<xsl:choose>
<xsl:when test="name(../../parent::*[1]) = 'section' and $strl > '2' and not(preceding-sibling::para)">
<xsl:apply-templates select="../@num" mode="next"/>
</xsl:when>
<xsl:otherwise>
<xsl:if test="not(preceding-sibling::para)">
<span class="item-num">
<xsl:value-of select="../@num"/>
</span>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="child::node()[not(self::para)]"/>
</div>
</xsl:for-each>
</li>
</xsl:template>
<xsl:template mode="next" match="@num">
<xsl:analyze-string select="." regex="([0-9]+)\.([0-9]+)\.([0-9]+)">
<xsl:matching-substring>
<a name="{concat('P',regex-group(1),'-',regex-group(2),'-',regex-group(3))}"/>
<span class="phrase">
<xsl:value-of select="."></xsl:value-of>
</span>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="." regex="([0-9]+)\.([0-9]+)">
<xsl:matching-substring>
<a name="{concat('P',regex-group(1),'-',regex-group(2))}"/>
<span class="phrase">
<xsl:value-of select="."></xsl:value-of>
</span>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."></xsl:value-of>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
<!-- <xsl:apply-templates select="../para"/></div>
</li>-->
</xsl:template>
<xsl:template match="page[not(preceding-sibling::node()[not(self::text()) or normalize-space()])]"/>
</xsl:transform>
主要的变化是简化
<?xml version="1.0" encoding="UTF-8"?>
<root>
<div class="para">
<div class="para">
<span class="phrase">
<a name="P1-4"/>1/4</span> 4.—(1) In these Rules, unless the context otherwise requires, the following expressions have the meanings hereby respectively assigned to them, namely:
<ol class="eng-orderedlist orderedlist">
<li class="item">
<div class="para">
<span class="item-num"/>“attend” includes the appearance by any person using electronic, mechanical or other means permitted by the Court;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“bailiff” includes the registrar, any clerk or other officer of the Court charged with the duties of a bailiff in the Subordinate Courts;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“Civil Procedure Convention” means the conventions set out in Appendix C to these Rules and includes any convention, treaty or agreement of any description or any provision thereof between different States relating to civil procedure in the court;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“folio” means 100 words, each figure being counted as one word;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“Form” means a form set out in Appendix A to these Rules, and a form so numbered in the Appendix;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“Judge” means a judge of the High Court or District Judge and includes, in cases where he is empowered to act, a Magistrate or the Registrar, as the case may require;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“officer” means an officer of the Supreme Court or Subordinate Courts;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“originating process” means a writ of summons or an originating summons;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“originating summons” means every summons for the commencement of proceedings other than a writ of summons;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“pleading” does not include an originating summons or preliminary act;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“receiver” includes a manager or consignee;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“Registry” means the Registry of the Supreme Court or the Registry of the Subordinate Courts, as the case may be, and references to the Registrar shall be construed accordingly;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“scheduled territories” has the meaning assigned to it by the Exchange Control Act (Chapter 99);</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“Sheriff” includes a bailiff of the Subordinate Courts;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“sign”, in relation to the signing of documents by the Registrar, includes the affixing of a facsimile signature;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“solicitor” has the same meaning as in the Legal Profession Act (Chapter 161);</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“summons” means every summons in a pending cause or matter.</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“working day” means any day other than a Saturday, Sunday or public holiday;</div>
</li>
<li class="item">
<div class="para">
<span class="item-num"/>“writ” means a writ of summons.</div>
</li>
</ol>
</div>
</div>
</root>
到
<div class="para">
<xsl:call-template name="phrase"/><!--
<xsl:variable name="content" select="generate-id(content-style[1])" />-->
<xsl:apply-templates select="child::node()[not(self::content-style)]"/>
然后删除 <div class="para">
<xsl:apply-templates/>
</div>
上的名称和模式属性以获取<xsl:template name="phrase" match="para/content-style[1]" mode="phrase">
。这样一切都落在了正确的地方。因此,基本上重要的一步是尽可能使用apply-templates和匹配模板,而不是尝试使用<xsl:template name="phrase" match="para/content-style[1]">
。如果您需要或想要使用call-template
,请记住它不会更改上下文节点,因此在匹配call-template
的模板中para
与命名模板继续处理{ {1}}元素。