2014-06-25 44 views
0

我有下面的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> 

这里还有一个paraorderedlist,当我跑我的模板,该orderedlist越来越对位即orderedlist里面的内容para内,后在orderedlist模板获取调用,我是来了很困惑为什么会发生这种情况。

这里是DEMO,请让我知道我该如何解决这个问题。

感谢

回答

1

你还没有告诉我们这导致你想,但根据您的匹配模式,它看起来就好像你现在想应用的模板上content-style但你call-template过程para元素的字符串值。

因此,我已经改变的代码如下:

<?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 &gt; '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> 

这导致http://xsltransform.net/eiZQaEP/1,其输出

<?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">名称和模式属性得到<xsl:template name="phrase" match="para/content-style[1]">。这样一切都落在了正确的位置。所以基本上重要的一步是尽可能地使用apply-templates和匹配模板,而不是试图使用call-template。如果您需要或想要使用call-template,请记住,它不会更改上下文节点,因此在匹配para a call-template的模板中与指定的模板继续处理该para元素。

+0

哇@Martin,谢谢你,这个作品很有魅力,请你详细解释一下我出错的地方以及你如何解决这个问题?再次感谢 – user2423959

+0

我已经对我所做的更改添加了一些解释。 –

相关问题