在XSL 2.0中,我试图通过不同的值迭代一些数据,然后用它们做一些事情。
<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.
我疯狂地谷歌搜索,我确实看到人们抱怨“原子价值”,但我还没有看到有人建议怎么做。我用的是Saxon9。任何见解将不胜感激。
答案 0 :(得分: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>