1 | <?xml version="1.0"?> |
---|
2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" |
---|
3 | xmlns:exsl="http://exslt.org/common" |
---|
4 | extension-element-prefixes="exsl"> |
---|
5 | |
---|
6 | <!-- |
---|
7 | analyzes the structure of xml-input: |
---|
8 | output: all xpaths |
---|
9 | strategy: 2 steps! : |
---|
10 | 1. flatten verbalize elements |
---|
11 | 2. aggregate |
---|
12 | --> |
---|
13 | |
---|
14 | <!-- <xsl:key name="names" match="NAME" use="concat('',@aliastype)"/> --> |
---|
15 | |
---|
16 | <xsl:key name="elem_names" match="elem" use="."/> |
---|
17 | |
---|
18 | <!-- |
---|
19 | <xsl:key name="divided_elems" match="*[@part]" use="concat(name(),':',@part)"/> |
---|
20 | <xsl:key name="person_unique" match="NXElem[@boldtype='Person']" use="concat(names/NXElem[xtype='default']/token,occs/NXElem[1]/occLocation,events/NXElem[xtype='birth']/date)"/> |
---|
21 | --> |
---|
22 | |
---|
23 | <xsl:param name="dataset" select="/" /> |
---|
24 | |
---|
25 | <xsl:variable name="flatted" > |
---|
26 | <xsl:call-template name="flatten" /> |
---|
27 | </xsl:variable> |
---|
28 | |
---|
29 | <xsl:template name="xml-ay" > |
---|
30 | <xsl:param name="dataset" select="$dataset"></xsl:param> |
---|
31 | |
---|
32 | <xsl:variable name="summarized"> |
---|
33 | <xsl:call-template name="summarize" > |
---|
34 | <xsl:with-param name="flatted"> |
---|
35 | <xsl:call-template name="flatten"> |
---|
36 | <xsl:with-param name="dataset" select="$dataset"></xsl:with-param> |
---|
37 | </xsl:call-template> |
---|
38 | </xsl:with-param> |
---|
39 | </xsl:call-template> |
---|
40 | </xsl:variable> |
---|
41 | <xsl:copy-of select="$summarized"></xsl:copy-of> |
---|
42 | </xsl:template> |
---|
43 | |
---|
44 | <xsl:template name="flatten"> |
---|
45 | <xsl:param name="dataset" select="$dataset"></xsl:param> |
---|
46 | <xsl:variable name="flatted"> |
---|
47 | <flatted> |
---|
48 | <xsl:for-each select="$dataset//*" > |
---|
49 | <elem n="{name()}"> |
---|
50 | <xsl:call-template name="path" /> |
---|
51 | </elem> |
---|
52 | </xsl:for-each> |
---|
53 | </flatted></xsl:variable> |
---|
54 | <xsl:copy-of select="$flatted"></xsl:copy-of> |
---|
55 | </xsl:template> |
---|
56 | |
---|
57 | <xsl:template name="summarize" > |
---|
58 | <xsl:param name="flatted" ></xsl:param> |
---|
59 | <xsl:message>count flatted <xsl:value-of select="count($flatted/flatted/elem)"></xsl:value-of></xsl:message> |
---|
60 | <!-- match="flatted" |
---|
61 | <xsl:for-each select="flatted/elem[generate-id() = generate-id(key('elem_names',.)[1])]" > --> |
---|
62 | <xsl:for-each-group select="$flatted/flatted/elem" group-by="."> |
---|
63 | <Term name="{@n}" path="{.}" count="{count(current-group())}" /> |
---|
64 | </xsl:for-each-group> |
---|
65 | </xsl:template> |
---|
66 | |
---|
67 | <xsl:template name="path" > |
---|
68 | <xsl:for-each select="ancestor::*" ><xsl:value-of select="name()" />/</xsl:for-each><xsl:value-of select="name()" /> |
---|
69 | </xsl:template> |
---|
70 | |
---|
71 | |
---|
72 | <!-- |
---|
73 | <xsl:template match="*[1]"> |
---|
74 | <xsl:param name="path" /> |
---|
75 | <xsl:value-of select="name()" /> |
---|
76 | <xsl:value-of select="count(../*[name()=name(current())])" /> |
---|
77 | <xsl:text>
</xsl:text> |
---|
78 | <xsl:apply-templates /> |
---|
79 | </xsl:template> |
---|
80 | --> |
---|
81 | |
---|
82 | </xsl:stylesheet> |
---|