Xsl: variable doesn't return node-set in XSLT 2.0?

I am trying to get node-set from xsl variable for calculation. But my code only works with Opera, with other browsers, I keep getting the error.

Please help me fix it working with all browsers. Thanks in advance.

Here is the xslt code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="html"/>

<xsl:variable name="multipleSet">
 <xsl:for-each select="myNums/numSet">
  <xsl:element name="multiple"><xsl:value-of select="num1 * num2"/></xsl:element>
 </xsl:for-each>
</xsl:variable>
<xsl:template match="/">
 <table border="1">
    <tr>
     <th>Num 1</th>
     <th>Num 2</th>
     <th>Multiple</th>
    </tr>
   <xsl:for-each select="myNums/numSet">
    <tr>
     <td><xsl:value-of select="num1"/></td>
     <td><xsl:value-of select="num2"/></td>
     <td><xsl:value-of select="num1 * num2"/></td>
    </tr>
   </xsl:for-each>
    <tr>
     <th colspan="2" align="right">Total:</th>
     <td><xsl:value-of select="sum($multipleSet/multiple)"/> </td>
    </tr>
 </table>
</xsl:template>
</xsl:stylesheet>

      

And the xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<myNums>
 <numSet>
  <num1>5</num1>
  <num2>5</num2>
 </numSet>
 <numSet>
  <num1>10</num1>
  <num2>5</num2>
 </numSet>
 <numSet>
  <num1>15</num1>
  <num2>20</num2>
 </numSet>
</myNums>

      

+2


a source to share


1 answer


Web browsers do not usually support xslt 2.0. Xpath sum () expects node-set. What you are passing is a "fragment of the result tree". In XSLT 1.1, the Result Tree Fragment data type was removed. So what are you experiencing:

  • Opera does not tell you an error message that it does not support xslt 2.0 ( Opera Specification )
  • Opera is not fully 1.0 compliant


You can try point version="1.1"

and see if it helps. Otherwise, you can try if browsers support exsl: node-set () .

0


a source







All Articles