tags:

views:

126

answers:

1

In XSL 2.0, I'm trying to iterate through some data by the distinct values, and then do something with them.

<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>

However I end up with the following error:

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.

I've bee googling furiously, and I do see people complaining about "atomic values" but I haven't seen anyone suggest what to do about it. I've using Saxon9. Any insight would be greatly appreciated.

A: 

Don't know if its the best solution, but this seems to work:

<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>
nont