[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to tell the number of distinct attribute values?
Yufei Wang wrote: > The rule is to re-group the items according to their @period value. > However, I could not figure out a way to tell how many distinct @period > values there are. Try the thing below. I've tested it with XT. Regards, Nikolai Grigoriev RenderX ====================================================== <!-- This template lists all grandchildren items sorted by @period --> <!-- and calls a group building template for every first occurrence --> <!-- of @period value (tested in xsl:if ). --> <xsl:template match="group"> <group> <xsl:for-each select="group/item"> <xsl:sort select="@period"/> <xsl:variable name="year" select="@period"/> <!-- Check if this value is mentioned for the first time --> <xsl:if test="not (preceding-sibling::item[@period=$year]) and not (../preceding-sibling::group/item[@period=$year])"> <xsl:apply-templates select="../.." mode="enumerate-items"> <xsl:with-param name="selected-year" select="$year"/> </xsl:apply-templates> </xsl:if> </xsl:for-each> </group> </xsl:template> <!-- This template builds a group of items for a given year. --> <!-- It is applied to the same node as the above one, but --> <!-- in a different mode. --> <xsl:template match="group" mode="enumerate-items"> <xsl:param name="selected-year"/> <group> <xsl:apply-templates select="group/item[@period=$selected-year]" mode="copy"/> </group> </xsl:template> <!-- Auxiliary template: when in copy mode, copy everything through --> <xsl:template match="*|@*|comment()|text()" mode="copy"> <xsl:copy> <xsl:apply-templates select="*|@*|comment()|text()" mode="copy"/> </xsl:copy> </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|