1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
2 |
|
---|
3 | <xsl:stylesheet version="1.0"
|
---|
4 | xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
|
---|
5 | xmlns:gslib="http://www.greenstone.org/skinning"
|
---|
6 | xmlns:java="http://xml.apache.org/xslt/java"
|
---|
7 | xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
|
---|
8 | xmlns:xalan="http://xml.apache.org/xalan"
|
---|
9 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
---|
10 | xmlns:xslt="output.xsl"
|
---|
11 | >
|
---|
12 |
|
---|
13 | <xsl:output method="xml"/>
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 | <xsl:template match="/">
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | <xsl:for-each select="/skinAndLibraryXsl/skinXsl/xsl:stylesheet">
|
---|
24 |
|
---|
25 | <!-- produce an exact copy of skin stylesheet, with gslib nodes expanded. -->
|
---|
26 | <xsl:variable name="element-name" select="name()"/>
|
---|
27 | <xsl:element name="{$element-name}">
|
---|
28 | <xsl:for-each select="@*">
|
---|
29 | <xsl:variable name="attribute-name" select="name()"/>
|
---|
30 | <xsl:attribute name="{$attribute-name}">
|
---|
31 | <xsl:value-of select="."/>
|
---|
32 | </xsl:attribute>
|
---|
33 | </xsl:for-each>
|
---|
34 |
|
---|
35 | <!-- merge the attributes of the library stylesheet -->
|
---|
36 | <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet/@*">
|
---|
37 | <xsl:variable name="attribute-name" select="name()"/>
|
---|
38 | <xsl:attribute name="{$attribute-name}">
|
---|
39 | <xsl:value-of select="."/>
|
---|
40 | </xsl:attribute>
|
---|
41 | </xsl:for-each>
|
---|
42 |
|
---|
43 | <xsl:call-template name="expand_gslib_elements" />
|
---|
44 |
|
---|
45 | <!-- add content of library to the skin stylesheet -->
|
---|
46 | <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet">
|
---|
47 | <xsl:call-template name="expand_gslib_elements" />
|
---|
48 | </xsl:for-each>
|
---|
49 |
|
---|
50 |
|
---|
51 | </xsl:element>
|
---|
52 |
|
---|
53 |
|
---|
54 | </xsl:for-each>
|
---|
55 | </xsl:template>
|
---|
56 |
|
---|
57 |
|
---|
58 | <!-- produce an exact copy of the current node, but expand and replace all elements belonging to the gslib namespace. -->
|
---|
59 | <xsl:template name="expand_gslib_elements">
|
---|
60 |
|
---|
61 |
|
---|
62 | <xsl:for-each select="*|text()">
|
---|
63 | <xsl:choose>
|
---|
64 |
|
---|
65 |
|
---|
66 | <!-- if node has gslib prefix, expand it into appropriate copy-of or call-template element -->
|
---|
67 | <xsl:when test="namespace-uri(.)=namespace::gslib">
|
---|
68 |
|
---|
69 | <xsl:variable name="name" select="local-name()"/>
|
---|
70 | <xsl:choose>
|
---|
71 |
|
---|
72 | <!-- if library contains a variable of this name, expand to it's value -->
|
---|
73 | <xsl:when test="/skinAndLibraryXsl/libraryXsl//xsl:variable[@name = $name]">
|
---|
74 | <xsl:element name="xsl:copy-of">
|
---|
75 | <xsl:attribute name="select">$<xsl:value-of select="local-name()" /></xsl:attribute>
|
---|
76 | </xsl:element>
|
---|
77 | </xsl:when>
|
---|
78 |
|
---|
79 |
|
---|
80 | <!-- if library contains a template of this name, expand to a call-template and pass attributes as parameters -->
|
---|
81 | <xsl:otherwise>
|
---|
82 | <xsl:element name="xsl:call-template">
|
---|
83 | <xsl:attribute name="name"> <xsl:value-of select="local-name()" /></xsl:attribute>
|
---|
84 |
|
---|
85 | <xsl:for-each select="@*">
|
---|
86 | <xsl:element name="xsl:with-param">
|
---|
87 | <xsl:attribute name="name"><xsl:value-of select="name()"/></xsl:attribute>
|
---|
88 | <xsl:call-template name="convert_attVal_to_valueOf" />
|
---|
89 | </xsl:element>
|
---|
90 | </xsl:for-each>
|
---|
91 | </xsl:element>
|
---|
92 | </xsl:otherwise>
|
---|
93 |
|
---|
94 | </xsl:choose>
|
---|
95 | </xsl:when>
|
---|
96 |
|
---|
97 | <xsl:when test="self::text()">
|
---|
98 | <xsl:value-of select="."/>
|
---|
99 | </xsl:when>
|
---|
100 |
|
---|
101 | <!-- if a regular node -->
|
---|
102 | <xsl:otherwise>
|
---|
103 | <xsl:variable name="element-name" select="name()"/>
|
---|
104 | <xsl:element name="{$element-name}">
|
---|
105 | <xsl:for-each select="@*">
|
---|
106 | <xsl:variable name="attribute-name" select="name()"/>
|
---|
107 | <xsl:attribute name="{$attribute-name}">
|
---|
108 | <xsl:value-of select="."/>
|
---|
109 | </xsl:attribute>
|
---|
110 | </xsl:for-each>
|
---|
111 | <xsl:call-template name="expand_gslib_elements" />
|
---|
112 | </xsl:element>
|
---|
113 | </xsl:otherwise>
|
---|
114 |
|
---|
115 |
|
---|
116 | </xsl:choose>
|
---|
117 | </xsl:for-each>
|
---|
118 |
|
---|
119 | </xsl:template>
|
---|
120 |
|
---|
121 | <!-- converts an attribute value (the current node) into either a literal value or an <xsl:value-of> element -->
|
---|
122 | <xsl:template name="convert_attVal_to_valueOf">
|
---|
123 |
|
---|
124 | <xsl:choose>
|
---|
125 | <!-- if attribute is not literal (starts with a "{") -->
|
---|
126 | <xsl:when test="starts-with(string(), '{')">
|
---|
127 | <xsl:element name="xsl:value-of">
|
---|
128 | <xsl:attribute name="disable-output-escaping">yes</xsl:attribute>
|
---|
129 | <xsl:attribute name="select"><xsl:value-of select="substring(string(),2,string-length()-2)"/></xsl:attribute>
|
---|
130 | </xsl:element>
|
---|
131 | </xsl:when>
|
---|
132 | <xsl:otherwise>
|
---|
133 | <xsl:value-of select="."/>
|
---|
134 | </xsl:otherwise>
|
---|
135 | </xsl:choose>
|
---|
136 | </xsl:template>
|
---|
137 |
|
---|
138 | <xsl:template name="create_dummy_variables">
|
---|
139 | <xsl:for-each select="//*[namespace-uri()=namespace::gslib]">
|
---|
140 | <xsl:element name="xsl:variable">
|
---|
141 | <xsl:attribute name="name">
|
---|
142 | <xsl:value-of select="local-name()"/>
|
---|
143 | </xsl:attribute>
|
---|
144 | </xsl:element>
|
---|
145 | </xsl:for-each>
|
---|
146 | </xsl:template>
|
---|
147 |
|
---|
148 |
|
---|
149 | </xsl:stylesheet>
|
---|