title: XSLT sum preceding siblings on attributes
body: <p>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:</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  &lt;xsl:template match="/xs:schema/xs:complexType/xs:sequence"&gt;
    &lt;html&gt;  &lt;body&gt;  &lt;table border="1"&gt;
      &lt;tr bgcolor="#9acd32"&gt;
        &lt;th&gt;Field&lt;/th&gt;
        &lt;th&gt;Width&lt;/th&gt;
        &lt;th&gt;Position&lt;/th&gt;
      &lt;/tr&gt;
      &lt;xsl:variable name="position" select="1"  /&gt;
      &lt;xsl:for-each select="xs:element"&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;xsl:value-of select="@name"/&gt;&lt;/td&gt;
        &lt;td&gt;&lt;xsl:value-of select="xs:simpleType/xs:restriction/xs:maxLength/@value"/&gt;&lt;/td&gt;
        &lt;td&gt;&lt;xsl:value-of select="sum(preceding-sibling::xs:simpleType/xs:restriction/xs:maxLength/@value)"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/xsl:for-each&gt;
    &lt;/table&gt;  &lt;/body&gt;  &lt;/html&gt;
  &lt;/xsl:template&gt;  &lt;/xsl:stylesheet&gt; 
  </code></pre>
  
  <p>The XML looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?xml-stylesheet type="text/xsl" href="fw.xsl"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:complexType name="xxxxxxxxxxxxx"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element default="" name="TransactionCode" nillable="true"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:maxLength value="2"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:element&gt;
        &lt;xs:element default="" minOccurs="0" name="ZipCodeSendingProgram" nillable="true"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:maxLength value="6"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:element&gt;
        &lt;xs:element default="" minOccurs="0" name="ZipCodeSendingProgramEOJ" nillable="true"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:maxLength value="3"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:element&gt;
        &lt;xs:element default="" minOccurs="0" name="ZipCodeError" nillable="true"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:string"&gt;
              &lt;xs:maxLength value="2"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:element&gt;
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>Field                     Width Position
  TransactionCode           2 0
  ZipCodeSendingProgram     6 2
  ZipCodeSendingProgramEOJ  3 8
  ZipCodeError              2 11
  </code></pre>
  
  <p>Actual output:</p>
  
  <pre><code>Field                     Width Position
  TransactionCode           2 0
  ZipCodeSendingProgram     6 0
  ZipCodeSendingProgramEOJ  3 0
  ZipCodeError              2 0
  </code></pre>
  
  <p>I am probably missing something really obvious...but I can't put my finger on it.
  Thanks in advance...</p>