Xslt 处理指令重复两次

Xslt 处理指令重复两次,xslt,Xslt,我有下面的XML <section level="sect1"> <title num="1.3"><content-style font-style="bold">Common Breaches</content-style></title> <page num="9"/> <section level="sect2"> <title><content-style font-style="bo

我有下面的XML

<section level="sect1">
<title num="1.3"><content-style font-style="bold">Common Breaches</content-style></title>
<page num="9"/>
<section level="sect2">
<title><content-style font-style="bolditalic">Non-payment of Rent/Service Charge/Hiring Charge/Licence Fee</content-style></title>
<orderedlist type="manual">
<item num="1.3.1"><para>The most common breach in a Tenancy Agreement is the late payment or non payment of rent. The Tenancy Agreement usually provides for the right of the Landlord to re-enter the premises and determine the tenancy upon non-payment of rent for a period of time. This is in addition to the Landlord&apos;s rights to sue the Tenant for any outstanding rent and any monies owing under the tenancy up to the expiry of the tenancy and forfeit the security deposit.</para></item>
<item num="1.3.2"><para>The Landlord may commence what are known as Writ of Distress proceedings or Writ of Summons proceedings to claim for the unpaid rent. The Writ of Distress is the more effective remedy, however only rent may be recovered under the Writ of Distress.</para></item>
</orderedlist>
</section>

常见违规行为
未缴付租金/服务费/租用费/牌照费
在租赁协议中,最常见的违约行为是迟交或不交租金。租赁协议通常规定业主有权在一段时间内未支付租金时重新进入该房屋并决定租赁。这是对房东的补充&apos;承租人有权起诉承租人,要求其支付任何未付租金和租赁到期前的任何欠款,并没收保证金。
业主可启动所谓的扣押令程序或传票程序,以索赔未付租金。扣押令是更有效的补救办法,但根据扣押令只能追讨租金。
我正在使用下面的XSLT

<xsl:template name="section" match="section">
    <!-- Variables-->
    <xsl:variable name="classname">
        <!--Get name attribute of current node -->
        <xsl:value-of select="concat('section-',@level)"/>
    </xsl:variable>
    <xsl:variable name="size">
        <xsl:value-of select="string-length(ancestor::chapter[1]/@num)"/>
    </xsl:variable>
    <xsl:variable name="Chn">
        <xsl:value-of select="ancestor::chapter[1]/@num"/>
    </xsl:variable>
    <xsl:variable name="chapternumber">
        <!-- Get num attribute of parent node -->
        <xsl:choose>
            <xsl:when test="$size=1">
                <xsl:value-of select="concat('0',$Chn)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$Chn"/>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:variable>
    <xsl:variable name="sectnum">
        <xsl:number level="any" count="section" format="1"/>
    </xsl:variable>
    <!--Create a string variable by concat string method  -->
    <xsl:variable name="sectionname">
        <xsl:value-of select="concat('CH_',$chapternumber,'-SEC-', $sectnum)"/>
    </xsl:variable>
    <!-- Template Content  -->
    <xsl:if test="./page[1]">
        <xsl:apply-templates select="./page[1]"/>
    </xsl:if>
    <div class="{$classname}">
        <a name="{$sectionname}"> </a>
        <div class="section-title">
            <xsl:if test="not(contains(./@num,'unnumbered'))">
                <xsl:if test="./title/@num">
                    <span class="section-num">
                        <a name="{concat('P',translate(./title/@num,'.','-'))}"></a>
                        <xsl:value-of select="./title/@num"/>
                    </span>
                    <xsl:text> </xsl:text>
                </xsl:if>
            </xsl:if>
              <xsl:apply-templates select="./title/child::node()[fn:not(self::page)]"/>
        </div>
        <!--<xsl:apply-templates select="child::node()[not(self::title)]"/>-->
    </div>
</xsl:template>

<xsl:template name="para" match="section/para">
    <xsl:choose>
        <xsl:when test="current()/@align">
            <div class="para align-{@align}">
                <xsl:apply-templates/>
            </div>
        </xsl:when>
        <xsl:when test="current()/@num">
            <xsl:choose>
                <xsl:when test="child::node()[1][self::*]">
                    <xsl:apply-templates select="child::page[1]"/>
                    <div class="para">
                        <xsl:call-template name="phrase"/>
                        <xsl:apply-templates select="child::node()[not(self::page)]"/>
                    </div>
                </xsl:when>
                <xsl:otherwise>
                    <div class="para">
                        <xsl:call-template name="phrase"/>
                        <xsl:apply-templates/>
                    </div>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
            <div class="para">
                <xsl:apply-templates/>
            </div>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="text()">
    <xsl:analyze-string select="." regex="(([Cc]hapter)\s(\d+))">
        <xsl:matching-substring>
            <xsl:choose>
                <xsl:when test="number(regex-group(3)) &lt; number(9)">
                    <a href="{concat('er:#MCCL_CH_',format-number(number(regex-group(3)),'00'),'/','MCCL_CH_',format-number(number(regex-group(3)),'00'))}">
                        <xsl:value-of select="."/>
                    </a>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="."/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
            <xsl:analyze-string select="." regex="[Pp]aragraphs\s([0-9]+)\.([0-9]+)\sand\s([0-9]+)\.([0-9]+)">
                <xsl:matching-substring>
                    <xsl:choose>
                        <xsl:when test="number(regex-group(1)) &lt; number(9)">
                            <a
                                href="{concat('er:#MCCL_CH_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
                                <xsl:value-of select="substring-before(., ' and')"/>
                            </a>
                            <xsl:text> and </xsl:text>
                            <a
                                href="{concat('er:#MCCL_CH_',format-number(number(regex-group(3)),'00'),'/P',format-number(number(regex-group(3)),'0'),'-',format-number(number(regex-group(4)),'000'))}">
                                <xsl:value-of select="substring-after(., 'and ')"/>
                            </a>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="."/>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:matching-substring>
                <xsl:non-matching-substring>
                    <xsl:analyze-string select="." regex="[Pp]aragraph\s([0-9]+)\.([0-9]+)">
                        <xsl:matching-substring>
                            <xsl:choose>
                                <xsl:when test="number(regex-group(1)) &lt; number(9)">
                                    <a
                                        href="{concat('er:#MCCL_CH_',format-number(number(regex-group(1)),'00'),'/P',format-number(number(regex-group(1)),'0'),'-',format-number(number(regex-group(2)),'000'))}">
                                        <xsl:value-of select="."></xsl:value-of>
                                    </a>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="."></xsl:value-of>
                                </xsl:otherwise>
                            </xsl:choose>
                        </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: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 name="orderitem" match="item">
    <xsl:choose>
        <xsl:when test="not(ends-with(@num, '.')) and fn:contains(@num,'.')">
            <xsl:apply-templates/>
        </xsl:when>
        <xsl:otherwise>
            <li class="item">
                <xsl:apply-templates/>
            </li>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="orderitempara" match="item/para">
    <xsl:choose>
        <xsl:when test="contains(../../@type,'manual')">
            <div class="para">
                <xsl:choose>
                    <xsl:when test="position()=1">
                        <xsl:choose>
                            <xsl:when test="contains(parent::item[1]/@num,'bull')">
                                <xsl:text>&#8226;</xsl:text>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:choose>
                                    <xsl:when test="not(ends-with(../@num, '.')) and fn:contains(../@num,'.')">
                                        <xsl:call-template name="phrase"/>
                                    </xsl:when>
                                    <xsl:when test="../@num">
                                        <span class="item-num">
                                            <xsl:apply-templates select="parent::item[1]/@num"/>
                                        </span>
                                    </xsl:when>
                                    <xsl:otherwise>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:otherwise>
                        </xsl:choose>
                        <xsl:text> </xsl:text>
                        <xsl:apply-templates/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates/>
                    </xsl:otherwise>
                </xsl:choose>
            </div>
        </xsl:when>
        <xsl:otherwise>
            <span class="bullet-list">
                <xsl:value-of select="../../@type"/>
            </span>
            <xsl:apply-templates/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="page">
    <xsl:processing-instruction name="pb">
        <xsl:text>label='</xsl:text>
        <xsl:value-of select="./@num"/>
        <xsl:text>'</xsl:text>
        <xsl:text>?</xsl:text>
    </xsl:processing-instruction>
  <a name="{concat('pg_',./@num)}"/>
    <xsl:apply-templates/>
</xsl:template>


<xsl:template name="phrase">
    <xsl:choose>
        <xsl:when test="parent::title">
            <xsl:variable name="phrase">
                <xsl:value-of select="concat('P',@num)"/>
            </xsl:variable>
            <xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
            <a>
                <xsl:attribute name="name">
                    <xsl:value-of select="$newphrase">
                    </xsl:value-of>
                </xsl:attribute>
            </a>
            <span class="phrase1">
                <xsl:value-of select="current()"/>
            </span>
        </xsl:when>
        <xsl:otherwise>
            <xsl:variable name="phrase">
                <xsl:value-of select="concat('P',../@num)"/>
            </xsl:variable>
            <xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
            <a>
                <xsl:attribute name="name">
                    <xsl:value-of select="$newphrase">
                    </xsl:value-of>
                </xsl:attribute>
            </a>
            <span class="phrase">
                <xsl:value-of select="../@num"/>
            </span>
        </xsl:otherwise>
    </xsl:choose>
    <!--<xsl:apply-templates/>-->


</xsl:template>
  • • 标签 ' ?
    当我运行这个程序时,我得到的输出如下

    这里的处理指令编号9(
    pb label='9'
    )正在复制,请告诉我如何获得以下输出


    谢谢

    让您的
    页面
    模板处于不同的模式

    <xsl:apply-templates select="page[1]" mode="insert_page"/>
    
    
    

    
    
    您还可以包括短语的模板吗?我已经运行了你的代码,没有复制你的错误。我在输出中只看到一条处理指令。您好@JoelM.Lamsen,很抱歉延迟回复,我已经用短语模板更新了答案。谢谢,我也在努力复制错误。看一看。请注意,将XSLT减少到复制问题的最低限度可能是值得的(例如,您有一个匹配
    text()
    的大模板,可以将其删除,以便触及问题的核心)。此外,您的XML格式不是很好,因为它缺少一个结束部分标记。谢谢您好@TimC,现在您可以看到错误了,我已经取消了“Thanka”的注释
    <xsl:template match="page" mode="insert_page">