I'm having trouble calling this template. I want to find the median "price" for all "widgets"
This is as far as I've gotten:
<xsl:call-template name="median">
<xsl:with-param name="nodes" select="*what goes here?*"/>
</xsl:call-template>
My XML:
<widgets>
<widget price="10" category="1" />
<widget price="5" category="1" />
<widget price="20" category="2" />
</widgets>
My XSL Template
*Found this in XSLT Cookbook
<xsl:template name="median">
<xsl:param name="nodes" select="/.."/>
<xsl:variable name="count" select="count($nodes)"/>
<xsl:variable name="middle" select="ceiling($count div 2)"/>
<xsl:variable name="even" select="not($count mod 2)"/>
<xsl:variable name="m1">
<xsl:for-each select="$nodes">
<xsl:sort data-type="number"/>
<xsl:if test="position() = $middle">
<xsl:value-of select=". + ($even * ./following-sibling::*[1])"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- The median -->
<xsl:value-of select="$m1 div ($even + 1)"/>
</xsl:template>
Any help is appreciated, thanks.