xsl:variable does not return a node-set in XSLT 2.0?
Posted
by Henry
on Stack Overflow
See other posts from Stack Overflow
or by Henry
Published on 2010-05-08T06:36:39Z
Indexed on
2010/05/08
6:48 UTC
Read the original article
Hit count: 207
xslt-2.0
Hi all,
I'm trying to get a node-set from a xsl variable for calculating. But my code only work with Opera, with other browsers, I keep getting the error.
Please help me fix to run with all browser. Thanks in advance.
Here are 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>
© Stack Overflow or respective owner