2013-07-17 23 views
0

我有以下xslt。for loop跳過內容並顯示更多數據

<?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="nomar"> 
<xsl:value-of select="./@country"/>  
    </div> 
     <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> 
    <div class="section-sect1"> 
    <xsl:text>Cases cited in the judgment</xsl:text> 
    </div> 
    <xsl:apply-templates select="//case.considered"/> 
    <div class="section-sec1"> 
    <xsl:apply-templates select="//other.mentioned"/> 
    </div> 
    </xsl:template> 

<xsl:template match="case.considered"> 
<xsl:for-each select="."> 
     <xsl:if test="./case.ref"> 
     <div class="para"> 
     <span class="font-style-italic"> 

      <xsl:value-of select="./case.ref/citetitle[@full]"/></span> 
    <xsl:text> </xsl:text>   
    <xsl:value-of select="./case.ref/citecitation/@full"/> 


     </div> 
     </xsl:if> 
    </xsl:for-each> 

</xsl:template> 

<xsl:template match="other.mentioned/other.ref"> 
<div class="para"> 
<xsl:value-of select="./author"/> 
<xsl:text>, </xsl:text> 
<span class="font-style-italic"> 
<xsl:value-of select="./book.title"/> 
</span> 
<xsl:text>, </xsl:text> 
<xsl:value-of select="ed_vol"/> 
<xsl:value-of select="./ref_grp/reference/pageno"/> 
</div> 
<xsl:apply-templates select="//judgment"/> 
</xsl:template> 

    <xsl:template match="judgment"> 
    <div class="section-sect1"> 
     <xsl:value-of select="./judge.block/heading"/> 
    </div> 
    <!--<xsl:for-each select="./judge.block/para.group"> 
     --><!--<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:apply-templates/> 
    </xsl:for-each>--> 
<xsl:apply-templates select="./judge.block/para.group"/> 
</xsl:template> 

<xsl:template match="judge.block/para.group"> 

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


     <xsl:if test="./block.quote"> 
     <xsl:for-each select="./block.quote/para.group"> 
     <div class="ali-itl"> 
      <xsl:value-of select="./heading"/> 
     </div> 
     <xsl:for-each select="./para.group"> 
     <div class="ali-itl"> 
      <xsl:value-of select="./heading"/> 
     </div> 
     <div class="extract"> 
     <div class="para"> 
      <xsl:apply-templates select="./para"/> 
     </div></div> 
     </xsl:for-each> 
     </xsl:for-each> 
     </xsl:if> 
    </xsl:for-each> 
<xsl:for-each select="./para.group"> 
<xsl:if test="./para.group"> 

<xsl:choose> 
    <xsl:when test="not(./para)"> 
     <div class="ital"> 
      <xsl:apply-templates select="./heading"/> 
     </div></xsl:when> 
     <xsl:otherwise> 
     <div class="ali-itl"> 
      <xsl:value-of select="./heading"/> 
     </div> 

     <div class="para"> 
      <span class="new"> 
      <xsl:value-of select="./para/label"/> 
     </span> 

      <xsl:value-of select="./para/text()"/> 
     </div> 
     </xsl:otherwise> 
</xsl:choose> 






     </xsl:if> 
    </xsl:for-each> 
    <xsl:if test="./block.quote"> 
     <xsl:for-each select="./block.quote/para.group"> 
     <div class="ali-itl"> 
      <xsl:value-of select="./heading"/> 
     </div> 
     <xsl:for-each select="./para.group"> 
     <div class="ali-itl"> 
      <xsl:value-of select="./heading"/> 
     </div> 
     <div class="extract"> 
     <div class="para"> 
     <div class="new"> 
     <xsl:value-of select="./para/label"/> 
     </div> 
      <xsl:apply-templates select="./para/text()"/> 
     </div></div> 
     </xsl:for-each> 
     </xsl:for-each> 
     </xsl:if> 



</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,輸出被跳過的內容(例如,我能夠看到編號[12]的內容,然後將其直接跳到在數字內容[16 ]並跳過它們之間的內容)。可以在以下鏈接中找到xml。 XML Doc。請讓我知道我哪裏錯了。

感謝

+0

只是爲了確保在我開始嘗試之前:您的XSLT能以某種方式最小化,所以只有您的特定問題和您的特定問題變得明顯嗎?沿着同樣的方向,你可以減少你的Xml文檔,只要足夠長的時間來顯示問題,所以它可以包含在你的問題中? –

+0

Hi @ O.R.Mapper,感謝您的回覆,我很抱歉地說我不能減少我的XML或XSLT,因爲xml不在流中。輸出是由上下流動產生的。謝謝 – user2423959

回答

0

這是真的很難從你給的信息說,但我覺得你的問題來自於一個事實,與「標籤」 13-15「段」元素居然騙內嵌套第二個 para.group元素內的第一個。 您的模板可能只能直接在「para.group」元素內匹配「para」元素,但不能嵌套「para.group」元素。

作爲局外人,基本上不可能在沒有太多時間投入分析您給出的大量輸入的情況下說出來,這可能是您爲什麼直到現在才收到其他答案的原因。

+0

非常感謝你的朋友,現在我明白了。 – user2423959