[xquery-talk] Doing some Pattern Frequency Distribution
Martin Probst
martin at x-hive.com
Thu Jun 8 00:53:31 PDT 2006
> This can be achieved in XQuery, but the grouping facility of XSLT 2.0
> makes it easier:
>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:variable name="zeroToNine" select="'0123456789'"/>
>
> <xsl:template match="/">
> <xsl:for-each-group select="//PHONE"
> group-by="translate(., $zeroToNine,
> '9999999999')">
> <xsl:value-of select="concat('Pattern: ',
> current-grouping-key(), '
> count: ',
> count(current-group()),
> '
' )"/>
> </xsl:for-each-group>
> </xsl:template>
>
> </xsl:stylesheet>
Corresponding:
for $phonenum in distinct-values(//PHONE/translate(., '0123456789',
'999999999'))
return
count(//PHONE[translate(., '0123456789', '999999999') eq $phonenum])
I'm not sure I find the XSLT solution easier, though it's might be
faster if your XQuery optimizer doesn't pick up the implicit grouping
logic (which is pretty likely, given the somewhat complicated join
condition).
Regards,
Martin
More information about the talk
mailing list