2013-07-16 42 views
0

使用循環發生,我下面的XSLT計算器是在我的代碼

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" exclude-result-prefixes="ntw"> 
    <xsl:output method="html"/> 
    <xsl:template match="/"> 
    <html> 
     <head> 
     <xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text> 
     <link rel="stylesheet" href="C:\Documents and Settings\u0138039\Desktop\Per\NEW.css" type="text/css"></link> 
     </head> 
     <body> 
     <section class="tr_chapter"> 
      <div class="chapter"> 
      <xsl:apply-templates/> 
      </div> 
     </section> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="case"> 
    <xsl:apply-templates select="case.head"/> 
    </xsl:template> 
    <xsl:template match="case.head"> 
    <div class="section-sect0"> 
     <div class="para"> 
     <xsl:value-of select="./party.line/party[@role='Plaintiff']"/> 
     </div> 
    </div> 
    <div class="section-sect0"> 
     <div class="para"> 
     <xsl:text disable-output-escaping="yes">V</xsl:text> 
     </div> 
    </div> 
    <div class="section-sect0"> 
     <div class="para"> 
     <xsl:value-of select="./party.line/party[@role='Defendant']"/> 
     </div> 
    </div> 
    <xsl:apply-templates select="case.ref.no.group | judge.line"/> 
    </xsl:template> 
    <xsl:template match="para"> 
    <div class="para"> 
     <xsl:apply-templates/> 
    </div> 
    </xsl:template> 

    <xsl:template match="case.ref.no.group"> 
    <div class="section-sect3"> 
     <span class="font-style-bold">Court of Appeal</span> 
     <xsl:text> - </xsl:text> 
     <xsl:value-of select="case.ref.no[1]/prefix" /> 
     <xsl:text> Nos. </xsl:text> 
     <xsl:for-each select="case.ref.no"> 
     <xsl:value-of select="number" /> 
     <xsl:text>-</xsl:text> 
     <xsl:value-of select="year" /> 
     <xsl:if test="not(position() = 2)"> 
     </xsl:if> 
     </xsl:for-each> 
    </div> 
    </xsl:template> 
    <xsl:template match="judge.line"> 
    <div class="section-sect3"> 
     <xsl:for-each select="judge"> 
     <xsl:value-of select="name"/> 
     <xsl:if test="not(position() = last())"> 
      <xsl:text>,</xsl:text> 
     </xsl:if> 
     </xsl:for-each> 
     <xsl:text> JC</xsl:text> 
    </div> 
    <xsl:apply-templates select="following-sibling::date.group"></xsl:apply-templates> 
    </xsl:template> 
    <xsl:template match="date.group"> 
    <div class="section-sect4"> 
     <div class="para"> 
     <xsl:value-of select="./date.line/date"/> 
     </div> 
    </div> 
    <xsl:apply-templates select="//catchwords.group"/> 
    </xsl:template> 
    <xsl:template match="catchwords.group"> 
    <div class="y"> 
     <xsl:for-each select="catchwords/catchword"> 
     <xsl:choose> 
      <xsl:when test="@level=1"><br/> 
      <span class="font-style-bolditalic"> 
       <xsl:value-of select="."/> 
      </span> 
      <xsl:text disable-output-escaping="yes">-</xsl:text> 
      </xsl:when> 
      <xsl:otherwise> 
      <xsl:for-each select="."> 
       <xsl:value-of select="."></xsl:value-of> 
       <xsl:if test="not(position() = last()-1)"> 
       <xsl:text disable-output-escaping="yes"> – </xsl:text> 
       </xsl:if> 
      </xsl:for-each> 
      </xsl:otherwise> 
     </xsl:choose> 
     </xsl:for-each> 
    </div> 
    <xsl:apply-templates select="//headnotes"/> 
    </xsl:template> 
    <xsl:template match="headnotes/para"> 
    <xsl:choose> 
     <xsl:when test="position()=1"> 
     <div class="x"> 
      <xsl:apply-templates></xsl:apply-templates> 
     </div> 
     </xsl:when> 
     <xsl:otherwise> 
     <div class="m"> 
      <xsl:apply-templates/> 
     </div> 
     </xsl:otherwise> 
    </xsl:choose> 
    <xsl:apply-templates select="para.group"/> 
    </xsl:template> 

    <xsl:template match="para.group"> 
    <div class="section-sect1"> 
     <xsl:value-of select="./heading"/> 
    </div> 
    <xsl:for-each select="./para"> 
     <xsl:apply-templates select="node()[not(self::label)]"/> 
    </xsl:for-each> 
    <xsl:apply-templates select="//counsel.group"/> 
    </xsl:template> 
    <xsl:template name="orderedlist" match="list"> 
    <ol class="eng-orderedlist orderedlist"> 
     <xsl:apply-templates select="list.item/label"/> 
    </ol> 
    </xsl:template> 
<xsl:template name="orderitempara" match="list.item/label"> 
    <li class="item"> 
     <div class="para"> 
     <span class="item-num"> 
      <xsl:choose> 
      <xsl:when test="following-sibling::case.considered"> 
       <xsl:apply-templates/> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:value-of select="."/> 
      </xsl:otherwise> 
      </xsl:choose> 
     </span> 
     <xsl:apply-templates select="parent::list.item"/> 
     </div> 
    </li> 
    </xsl:template> 

    <xsl:template match="list.item"> 
    <xsl:variable name="a"> 
     <xsl:value-of select="./label"/> 
    </xsl:variable> 
    <xsl:choose> 
     <xsl:when test="./label"> 
     <xsl:apply-templates select="child::node()[not(self::label|case.ref)]"/> 
     </xsl:when> 
    </xsl:choose> 
    </xsl:template> 

    <xsl:template match="counsel.group" name="j"> 
<div class="ital"> 
    <xsl:for-each select="./counsel.line"> 
     <div class="para"> 
     <xsl:value-of select="."/> 
     </div> 
    </xsl:for-each> 
    <xsl:text disable-output-escaping="yes">Judgment received: December 4, 2008</xsl:text> 
    </div> 
    <xsl:apply-templates select="//ref.group"/> 
    </xsl:template> 
    <xsl:template match="ref.group/leg.mentioned"> 
    <div class="section-sect1"> 
     <xsl:text>Legislation mentioned in the judgment</xsl:text> 
    </div> 
    <xsl:for-each select="./leg.ref"> 
     <div class="para"> 
     <xsl:value-of select="./citetitle"/> 
     <xsl:text>, </xsl:text> 
     <xsl:for-each select="./leg.ptr.group/leg.ptr"> 
      <xsl:value-of select="."/> 
      <xsl:if test="not(position() = last())"> 
      <xsl:text disable-output-escaping="yes">, </xsl:text> 
      </xsl:if> 
     </xsl:for-each> 
     </div> 
    </xsl:for-each> 
    <xsl:text>Cases cited in the judgment</xsl:text> 
    <xsl:for-each select="//citetitle"> 
     <xsl:if test="parent::case.ref/@annotation"> 
     <div class="ital"> 
      <div class="para"> 
      <xsl:value-of select="."/> 
      <xsl:value-of select="//citecitation"/> 
      <xsl:value-of select="parent::case.ref/@court"/> 
      <xsl:text> (</xsl:text> 
      <xsl:value-of select="parent::case.ref/@annotation"/> 
      <xsl:text>)</xsl:text> 
      </div> 
     </div> 
     </xsl:if> 
    </xsl:for-each> 
    <xsl:apply-templates select="//judgment"/> 
    </xsl:template> 

    <xsl:template match="judgment"> 
    <div class="section-sect1"> 
     <xsl:value-of select="./judge.block/heading/judgename"/> 
    </div> 
    <xsl:for-each select="./judge.block/para"> 
     <div class="para"> 
     <span class="new"> 
      <xsl:value-of select="./label"></xsl:value-of> 
     </span> 
     <xsl:value-of select="./text()"/> 
     </div> 
     <xsl:apply-templates select="./list"/> 
    </xsl:for-each> 

    <xsl:for-each select="./judge.block/para.group"> 
     <xsl:if test="./heading"> 
     <div class="section-sect1"> 
      <xsl:value-of select="./heading/text()"/> 
     </div> 
     </xsl:if> 
     <xsl:for-each select="para"> 
     <div class="para"> 
      <span class="new"> 
      <xsl:value-of select="./label"></xsl:value-of> 
      </span> 
      <xsl:apply-templates select="child::node()[not(self::label)]"/> 
     </div> 
     <xsl:apply-templates select="./list"/> 
     </xsl:for-each> 
    </xsl:for-each> 
    </xsl:template> 
    <xsl:template match="emphasis"> 
    <xsl:choose> 
     <xsl:when test="citetitle"> 
     <span class="font-style-italic"> 
      <xsl:apply-templates select="./list.item"/> 
     </span> 
     </xsl:when> 
     <xsl:when test="./@type"> 
     <xsl:variable name="fontStyle"> 
      <xsl:value-of select="concat('font-style-',@type)"/> 
     </xsl:variable> 
     <span class="{$fontStyle}"> 
      <xsl:apply-templates/> 
     </span> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:apply-templates/> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 
</xsl:stylesheet> 

當我申請這對我的我的XML這是給我一個計算器錯誤的下面部分。

<?xml version="1.0" encoding="UTF-8"?> 
<case> 
<counsel.group> 
      <counsel.line>Azar Irwan b Moh Arifin (AG&#x2019;s Chambers) for Public Prosecutor</counsel.line> 
      <counsel.line>SK Pari (Pari &amp; Co) for first accused</counsel.line></counsel.group> 
<ref.group> 
     <leg.mentioned> 
      <leg.ref country="India"> 
       <citetitle type="leg" legtype="ord">Indian Penal Code</citetitle> 
       <leg.ptr.group> 
        <leg.ptr provision="s" print="yes">302</leg.ptr> 
       </leg.ptr.group> 
      </leg.ref> 
      <leg.ref country="Malaysia"> 
       <citetitle type="leg" legtype="ord">Criminal Procedure Code</citetitle> 
       <leg.ptr.group> 
        <leg.ptr provision="ss" print="yes">112</leg.ptr> 
        <leg.ptr provision="s" print="no">112</leg.ptr> 
            </leg.ptr.group> 
      </leg.ref> 

      <leg.ref country="Malaysia"> 
       <citetitle type="leg" legtype="ord">Penal Code</citetitle> 
       <leg.ptr.group> 
        <leg.ptr provision="ss" print="yes">109</leg.ptr> 
        <leg.ptr provision="s" print="no">299</leg.ptr> 

       </leg.ptr.group> 
      </leg.ref> 
     </leg.mentioned></ref.group> 
</case> 

請讓我知道我該如何解決這個錯誤以及要遵循哪些步驟以便將來我不會遇到這個錯誤。 謝謝

+0

我用Saxon 6.5.5試過了你的例子,它輸出一小段HTML樣本而沒有給出任何錯誤。你使用哪種XSLT處理器?確切的錯誤信息是否表明錯誤發生在哪條線和/或模板上?通常,堆棧溢出意味着發生了一種遞歸,因爲XSLT代碼中的無限遞歸或深層嵌套的XML輸入,堆棧空間比可用空間多。 –

+0

嗨@MartinHonnen我使用altova xml間諜,我面臨的錯誤是在。謝謝你的回覆,我不能粘貼我的整個XML文檔,因爲它很大,你可以請你的電子郵件地址,這樣我會通過電子郵件發送給你的文檔,然後你可以粘貼在這裏的決議。謝謝 – user2423959

+0

您可以將您的XML發佈到PasteBin,以便我們都可以看到它。我剛剛在Visual Studio中嘗試了您的XSLT和XML,並且沒有錯誤地完成。 – JLRishe

回答

0

您的XSLT包含一個無限循環。你para.group模板包含這樣的:

<xsl:apply-templates select="//counsel.group"/> 

然後爲counsel.group模板具有這樣的:

<xsl:apply-templates select="//ref.group"/> 

ref.group模板具有這樣的:

<xsl:apply-templates select="//judgment"/> 

judgment模板有這樣的:

<xsl:for-each select="para"> 
    ... 
     <xsl:apply-templates select="child::node()[not(self::label)]"/> 
    ... 
    </xsl:for-each> 

該級聯可以在para.group上應用模板,然後回到開始階段。這個過程循環進行,直到堆棧溢出。我認爲你需要重新思考你的XSLT來找出如何防止無限遞歸。