Project

Profile

Help

How to connect?
Download (1.09 KB) Statistics
| Branch: | Tag: | Revision:

he / tags / 9.8.0.14 / samples / styles / summarize.xsl @ 02f8308b

1
<xsl:transform
2
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
4
 xmlns:f="http://localhost/functions"
5
 exclude-result-prefixes="xs f"
6
 version="3.0"
7
>
8

    
9
<!-- This stylesheet summarizes the contents of the input XML file, displaying
10
     the names of the elements encountered and the number of occurrences of each -->
11

    
12
<xsl:output method="xml" indent="yes"/>
13

    
14
<xsl:param name="include-attributes" as="xs:boolean" select="false()"/>
15

    
16
<xsl:template match="/">
17
  <summary of="{document-uri(.)}">
18
    <xsl:for-each-group select="//* | //@*[$include-attributes]" group-by="f:path(.)">
19
      <xsl:sort select="current-grouping-key()"/>
20
      <element path="{current-grouping-key()}" count="{count(current-group())}"/>
21
    </xsl:for-each-group>
22
  </summary>
23
</xsl:template>
24

    
25
<xsl:function name="f:path" as="xs:string" visibility="public">
26
  <xsl:param name="node" as="node()"/>
27
  <xsl:sequence select="$node/(
28
    if (. instance of attribute())
29
    then concat(f:path(..), '/@', name())
30
    else string-join(ancestor-or-self::*/name(), '/'))"/>
31
</xsl:function>
32

    
33

    
34
</xsl:transform>	
(10-10/12)