source: greenstone3/trunk/web/ui/xslt/preProcess.xsl@ 20157

Last change on this file since 20157 was 20157, checked in by kjdon, 15 years ago

explicitly write out the xsl:stylesheet element with its namespaces as they don't seem to come through with new xalan.

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