Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Subject: Counting Path Occurrences

From: "Scott Coon" <scoon@------------->
To:
Date: 4/4/2007 2:24:00 AM
Michael Kay wrote:
> Scott Coon wrote:
> > 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.

That was the original source of my confusion.  :)  Is that because of
the "for-each" over the ancestor-or-self axis?

> >
> > 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>
>

I want to make sure I understand this:  is the "xsl:sequence" operation
constructing a sequence that contains the results of the "select"
attribute?  And does that result in a single text node because of the
concat?  And is that enforced at runtime by the "as" attribute in your
function declaration?

Thanks,
Scott


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent