2009-09-30 22 views
1

在XSL 2.0中,我試圖通過不同的值迭代一些數據,然後對它們做些什麼。爲什麼我無法使用此xpath表達式中的子元素進行導航?

<xsl:for-each select="distinct-values(InvoiceLine/Service/ServiceMnemonicCode)">     
    <xsl:variable name="mnemonic"> 
    <xsl:value-of select="."/> 
    </xsl:variable> 
     <fo:table-row> 
      <fo:table-cell> 
       <fo:block> 
<xsl:value-of select="InvoiceLine/Service[ServiceMnemonic=$mnemonic]/ServiceDescription"/>      
       </fo:block> 
      </fo:table-cell> 
     </fo:table-row> 
</xsl:for-each> 

但是我結束了以下錯誤:

XPTY0020: Axis step 
child::element({http://schemas.blabla.com/etp/invoice/types}InvoiceLine, xs:anyType) 
cannot be used here: the context item is an atomic value 
ailed to compile stylesheet. 1 error detected. 

我有蜜蜂瘋狂google搜索,我的確看到人們抱怨「原子值」,但我還沒有看到任何人有什麼建議去做。我已經使用Saxon9。任何有識之士將不勝感激。

+1

本頁面似乎對大家有點幫助: http://www.oxygenxml.com/forum/topic3882.html – nont 2009-10-01 19:27:39

回答

0

不知道它的最好的解決辦法,但是這似乎工作:

<xsl:template match="Invoice"> 
     <xsl:variable name="invoice"> 
      <xsl:copy-of select="."/> 
     </xsl:variable> 
     <fo:table border="0.5pt solid black" text-align="center"> 
      <fo:table-body> 
       <xsl:for-each select="distinct-values(InvoiceLine/Service/ServiceMnemonicCode)"> 
        <xsl:sort/> 
        <xsl:variable name="code"> 
         <xsl:copy-of select="."/> 
        </xsl:variable> 
        <fo:table-row> 
         <fo:table-cell> 
          <fo:block> 
           <xsl:value-of select="($invoice/node()/InvoiceLine/Service[ServiceMnemonicCode=$code]/ServiceDescription)[1]"/> 
          </fo:block> 
         </fo:table-cell> 
        </fo:table-row> 
       </xsl:for-each> 
      </fo:table-body> 
     </fo:table> 
    </xsl:template> 
相關問題