Debian Codegraph @

tools/paramextract.xsl

raw
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
3
4 <xsl:output indent="yes"/>
5
6 <!--
7 Extract all the parameters from the XSL stylesheets.
8 Example of use:
9
10 xsltproc extractparam.xsl docbook.xsl > paramgroup.xml
11 xsltproc -.-param chunk 1 extractparam.xsl docbook.xsl
12 -->
13 <xsl:param name="chunk" select="0"/>
14 <xsl:param name="chunk.prefix" select="''"/>
15 <xsl:param name="chunk.suffix" select="'sxml'"/>
16
17 <xsl:include href="../xsl/chunker.xsl"/>
18
19 <xsl:template match="/">
20 <xsl:choose>
21 <xsl:when test="$chunk = 0">
22 <xsl:element name="xsl:paramgroup">
23 <xsl:apply-templates select="xsl:stylesheet"/>
24 </xsl:element>
25 </xsl:when>
26 <xsl:otherwise>
27 <xsl:apply-templates select="xsl:stylesheet"/>
28 </xsl:otherwise>
29 </xsl:choose>
30 </xsl:template>
31
32 <xsl:template match="@*|node()">
33 <xsl:copy>
34 <xsl:apply-templates select="@*|node()"/>
35 </xsl:copy>
36 </xsl:template>
37
38 <xsl:template match="xsl:param">
39
40 <xsl:message>
41 <xsl:value-of select="@name"/>
42 <xsl:text> = </xsl:text>
43 <xsl:choose>
44 <xsl:when test=". != ''">
45 <xsl:value-of select="."/>
46 <xsl:text> (string)</xsl:text>
47 </xsl:when>
48 <xsl:when test="@select">
49 <xsl:value-of select="@select"/>
50 <xsl:text> (select) </xsl:text>
51 <xsl:choose>
52 <xsl:when test="@select = number(@select)">
53 <xsl:text> (number) </xsl:text>
54 </xsl:when>
55 <xsl:otherwise>
56 <xsl:text> (string) </xsl:text>
57 </xsl:otherwise>
58 </xsl:choose>
59 </xsl:when>
60 <xsl:otherwise>
61 <xsl:text> (empty) </xsl:text>
62 </xsl:otherwise>
63 </xsl:choose>
64 </xsl:message>
65
66 <!-- copy the parameter -->
67 <xsl:variable name="param">
68 <xsl:element name="xsl:param">
69 <xsl:apply-templates select="@*|node()" />
70 </xsl:element>
71 </xsl:variable>
72
73 <!-- put it in the main stream, or chunk as a new file -->
74 <xsl:choose>
75 <xsl:when test="$chunk = 0">
76 <xsl:copy-of select="$param"/>
77 </xsl:when>
78 <xsl:otherwise>
79 <xsl:call-template name="write.chunk">
80 <xsl:with-param name="filename">
81 <xsl:value-of select="$chunk.prefix"/>
82 <xsl:value-of select="@name"/>
83 <xsl:text>.</xsl:text>
84 <xsl:value-of select="$chunk.suffix"/>
85 </xsl:with-param>
86 <xsl:with-param name="omit-xml-declaration" select="'yes'"/>
87 <xsl:with-param name="method" select="'xml'"/>
88 <xsl:with-param name="content" select="$param"/>
89 <xsl:with-param name="indent" select="'yes'"/>
90 </xsl:call-template>
91 </xsl:otherwise>
92 </xsl:choose>
93
94 </xsl:template>
95
96
97 <xsl:template match="xsl:stylesheet">
98 <xsl:apply-templates select="xsl:param"/>
99 <xsl:apply-templates select="xsl:include"/>
100 </xsl:template>
101
102
103 <xsl:template match="xsl:include">
104 <xsl:variable name="doc" select="document(@href)"/>
105
106 <xsl:message>Params defined in <xsl:value-of select="@href"/></xsl:message>
107
108 <xsl:apply-templates select="$doc/xsl:stylesheet"/>
109 </xsl:template>
110
111 </xsl:stylesheet>