R
Rolf Kemper
Dear Experts,
right on time before Xmas I have something to think about.
I want to sum up values by using a key. But the value which is used as
a selctor in the key function is a node-set.
I made a smal test program and run it with 3 pocessors.
ALTOVA (XMLSPY 2005) , MSXML4 , SAXON 8.
The results and messages differ !
ALTOVA( = 1300 (which was my expectation)
MSXML4 = 600 (which is may be right, but not was was expecting)
SAXON8 = 600 ( with additional warning )
1) What is correct way to make my dream come true ?
2) Why does SAXON complain (I'm using XSLT version 1.0 )
Plaese find below a test case
Thanks for your inputs and marry Christmas
Rolf
################# xml data ##################################
<?xml version="1.0" encoding="UTF-8"?>
<SumTest>
<Cells>
<Cell Name="A" Size="100"/>
<Cell Name="B" Size="200"/>
<Cell Name="C" Size="300"/>
</Cells>
<Instancies>
<Instance InstName="I1" CellName="A" Index="1" /><!-- 100 -->
<Instance InstName="I2" CellName="B" Index="2" /><!-- 200 -->
<Instance InstName="I3" CellName="A" Index="3" /><!-- 100 -->
<Instance InstName="I4" CellName="A" Index="4" /><!-- 100 -->
<Instance InstName="I5" CellName="C" Index="5" /><!-- 300 -->
<Instance InstName="I6" CellName="C" Index="6" /><!-- 300 -->
<Instance InstName="I7" CellName="B" Index="7" /><!-- 200 -->
<Instance InstName="I8" CellName="B" Index="8" /><!-- unselected-->
<Instance InstName="I9" CellName="C" Index="9" /><!-- unselected-->
</Instancies>
<!-- 3*A = 300 + 2*B = 400 + 2*C = 600 should sum up to 1300 -->
<!-- altova = 1300 (which might be OK just by different
interpretation of key/sum ) -->
<!-- msxml4 = 600 ( which is A+B+C probably first occurence of node
is used as key valu probably ) -->
<!-- saxon8 = 600 ( which is A+B+C probably first occurence of
node is used as key valu probably )
WARNING on compare !! comparsion of a node-set to a boolean has
changed dsince XPATH 1.0 "
-->
</SumTest>
################## xslt #######################################
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text" version="1.0" encoding="UTF-8"/>
<xsl:key name="kCells" match="/SumTest/Cells/Cell" use="@Name"/>
<xsl:variable name="gEndIndex"
select="/SumTest/Instancies/Instance[@InstName='I8']/@index"/>
<xsl:variable name="gInstancies"
select="/SumTest/Instancies/Instance[@Index > 0 and @index <
$gEndIndex ]"/>
<xsl:variable name="vSumSize" select="sum(
key('kCells',$gInstancies/@CellName)/@Size)"/>
<xsl:template match="/">
<xsl:text>selected node count =</xsl:text>
<xsl:value-of select="count($gInstancies)"/>
<xsl:text>
</xsl:text>
<xsl:text>SumSize=</xsl:text>
<xsl:value-of select="$vSumSize"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
######################## END ############################
right on time before Xmas I have something to think about.
I want to sum up values by using a key. But the value which is used as
a selctor in the key function is a node-set.
I made a smal test program and run it with 3 pocessors.
ALTOVA (XMLSPY 2005) , MSXML4 , SAXON 8.
The results and messages differ !
ALTOVA( = 1300 (which was my expectation)
MSXML4 = 600 (which is may be right, but not was was expecting)
SAXON8 = 600 ( with additional warning )
1) What is correct way to make my dream come true ?
2) Why does SAXON complain (I'm using XSLT version 1.0 )
Plaese find below a test case
Thanks for your inputs and marry Christmas
Rolf
################# xml data ##################################
<?xml version="1.0" encoding="UTF-8"?>
<SumTest>
<Cells>
<Cell Name="A" Size="100"/>
<Cell Name="B" Size="200"/>
<Cell Name="C" Size="300"/>
</Cells>
<Instancies>
<Instance InstName="I1" CellName="A" Index="1" /><!-- 100 -->
<Instance InstName="I2" CellName="B" Index="2" /><!-- 200 -->
<Instance InstName="I3" CellName="A" Index="3" /><!-- 100 -->
<Instance InstName="I4" CellName="A" Index="4" /><!-- 100 -->
<Instance InstName="I5" CellName="C" Index="5" /><!-- 300 -->
<Instance InstName="I6" CellName="C" Index="6" /><!-- 300 -->
<Instance InstName="I7" CellName="B" Index="7" /><!-- 200 -->
<Instance InstName="I8" CellName="B" Index="8" /><!-- unselected-->
<Instance InstName="I9" CellName="C" Index="9" /><!-- unselected-->
</Instancies>
<!-- 3*A = 300 + 2*B = 400 + 2*C = 600 should sum up to 1300 -->
<!-- altova = 1300 (which might be OK just by different
interpretation of key/sum ) -->
<!-- msxml4 = 600 ( which is A+B+C probably first occurence of node
is used as key valu probably ) -->
<!-- saxon8 = 600 ( which is A+B+C probably first occurence of
node is used as key valu probably )
WARNING on compare !! comparsion of a node-set to a boolean has
changed dsince XPATH 1.0 "
-->
</SumTest>
################## xslt #######################################
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="text" version="1.0" encoding="UTF-8"/>
<xsl:key name="kCells" match="/SumTest/Cells/Cell" use="@Name"/>
<xsl:variable name="gEndIndex"
select="/SumTest/Instancies/Instance[@InstName='I8']/@index"/>
<xsl:variable name="gInstancies"
select="/SumTest/Instancies/Instance[@Index > 0 and @index <
$gEndIndex ]"/>
<xsl:variable name="vSumSize" select="sum(
key('kCells',$gInstancies/@CellName)/@Size)"/>
<xsl:template match="/">
<xsl:text>selected node count =</xsl:text>
<xsl:value-of select="count($gInstancies)"/>
<xsl:text>
</xsl:text>
<xsl:text>SumSize=</xsl:text>
<xsl:value-of select="$vSumSize"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
######################## END ############################