I'm trying to sum all the previous values for a specific attribute. I figured the use of sum and preceding-sibling would do the trick. I am getting all zeroes instead. Here is the XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="/xs:schema/xs:complexType/xs:sequence">
<html> <body> <table border="1">
<tr bgcolor="#9acd32">
<th>Field</th>
<th>Width</th>
<th>Position</th>
</tr>
<xsl:variable name="position" select="1" />
<xsl:for-each select="xs:element">
<tr>
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="xs:simpleType/xs:restriction/xs:maxLength/@value"/></td>
<td><xsl:value-of select="sum(preceding-sibling::xs:simpleType/xs:restriction/xs:maxLength/@value)"/></td>
</tr>
</xsl:for-each>
</table> </body> </html>
</xsl:template> </xsl:stylesheet>
The XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="fw.xsl"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="xxxxxxxxxxxxx">
<xs:sequence>
<xs:element default="" name="TransactionCode" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element default="" minOccurs="0" name="ZipCodeSendingProgram" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="6"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element default="" minOccurs="0" name="ZipCodeSendingProgramEOJ" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element default="" minOccurs="0" name="ZipCodeError" nillable="true">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Expected output:
Field Width Position
TransactionCode 2 0
ZipCodeSendingProgram 6 2
ZipCodeSendingProgramEOJ 3 8
ZipCodeError 2 11
Actual output:
Field Width Position
TransactionCode 2 0
ZipCodeSendingProgram 6 0
ZipCodeSendingProgramEOJ 3 0
ZipCodeError 2 0
I am probably missing something really obvious...but I can't put my finger on it. Thanks in advance...