This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

newbie: xsl:key and summation of substrings


hi

Despite reading the faqs, I am still banging my head on basic summation and
would appreciate help.

I have a repeating element that looks something like this:
           <disk>
     <freespace>1235 MB</freespace>
           </disk>
           <disk>
     <freespace>40 MB</freespace>
           </disk>
           <disk>
     <freespace>75  MB</freespace>
           </disk>


I want to sum the "freespace", but sum(//disk/freespace) won't work because
freespace is not a number due to the trailing "MB".
Of course, sum(substring-before(//disk/freespace, ' ')) does not work...

So I thought the solution lies in  building an index of freespace values:

     <xsl:key name="freespace" match="//disk" use
="substring-before(freespace,' ')"/>

     <!-- output sum of freespace values: -->
                <total>
         <xsl:value-of select="sum(key('freespace',.))"/>
     </total>

.. but it doesn't.

I can not influence the content of this source document.
How do I best sum over elements which need to be substring-parsed?

I realize this is basic. I'm just not getting the examples in the faq.

Thanks, chris






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]