|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Subject: Counting Path Occurrences
> So, start with a stylesheet function to generate the paths > (/a/b/x) using the ancestor-or-self axis: > > <xsl:function name="gn:path"> > <xsl:param name="node" as="node()"/> > <xsl:for-each select="$node"> > <xsl:for-each select="ancestor-or-self::*"><xsl:value-of > select="concat('/', name())"/></xsl:for-each> > </xsl:for-each> > </xsl:function> Actually that function generates a sequence of text nodes. > > My hope was to use it like this in the template that matches "/": > > <xsl:for-each-group select="descendant-or-self::*" > group-by="gn:path(.)"> > Path: <xsl:value-of select="gn:path(.)"/> - Count: > <xsl:value-of select="count(current-group())"/> </xsl:for-each-group> > > Unfortunately, stylesheet functions only return item()*, not > string, Stylesheet functions return whatever you choose them to return. The simplest way to return the string you want is <xsl:function name="gn:path" as="xs:string"> <xsl:param name="node" as="node()"/> <xsl:sequence select="concat('/', string-join(ancestor-or-self::*/name(), '/'))"/> </xsl:function> Michael Kay http://www.saxonica.com/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Cast Your Vote
We need your help – Vote for DataDirect XML Products!
Winners and finalists announced at SOA World Conference in November. 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
|







