xsl-list
[Top] [All Lists]

Re: [xsl] How to make this XSLT works for more than two section

2012-06-15 10:55:59
   <xsl:function name="custom:equalPredecingItemCount" as="xs:integer">
     <xsl:param name="preceding_items"/>
     <xsl:param name="this_item"/>
     <xsl:value-of select="sum(for $item in $preceding_items return 
custom:getEqualityValue($item, $this_item))"/>
   </xsl:function>

   <xsl:function name="custom:getEqualityValue" as="xs:integer">
     <xsl:param name="item1"/>
     <xsl:param name="item2"/>
     <xsl:value-of select="if (deep-equal($item1, $item2)) then 1 else 0"/>
   </xsl:function>

A tip here - when the sequence type (as attribute) of the function is
an atomic, always use xsl:sequence instead of xsl:value-of.

When you use value-of you create a text node, which then gets atomized
to the sequence type, so you can avoid that unnecessary step by using
xsl:sequence which will return an atomic.

The general rule is 'always use xsl:sequence in xsl:functions', as you
pretty much always return atomics from functions.

(that's also a good interview question "what's the difference between
xsl:sequence and xsl:value-of)


-- 
Andrew Welch
http://andrewjwelch.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


<Prev in Thread] Current Thread [Next in Thread>