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

Last change on this file since 21000 was 20160, checked in by oranfry, 15 years ago
  • let the xsl transformer copy the xmlns declarations instead of entering them explicitly
  • added a missing namespace declaration in util of default skin
  • svn:ignored xalan.jar as it exists in the repository as xalan.jar.tmp
File size: 4.8 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>
23
24 <xsl:for-each select="/skinAndLibraryXsl/skinXsl/xsl:stylesheet">
25
26 <!-- produce an exact copy of skin stylesheet, with gslib nodes expanded. -->
27 <xsl:for-each select="@*">
28 <xsl:variable name="attribute-name" select="name()"/>
29 <xsl:attribute name="{$attribute-name}">
30 <xsl:value-of select="."/>
31 </xsl:attribute>
32 </xsl:for-each>
33 <!-- merge the attributes of the library stylesheet -->
34 <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet/@*">
35 <xsl:variable name="attribute-name" select="name()"/>
36 <xsl:attribute name="{$attribute-name}">
37 <xsl:value-of select="."/>
38 </xsl:attribute>
39 </xsl:for-each>
40
41 <xsl:call-template name="expand_gslib_elements" />
42
43 <!-- add content of library to the skin stylesheet -->
44 <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet">
45 <xsl:call-template name="expand_gslib_elements" />
46 </xsl:for-each>
47
48 </xsl:for-each>
49 </xslt:stylesheet>
50
51
52 </xsl:template>
53
54
55 <!-- produce an exact copy of the current node, but expand and replace all elements belonging to the gslib namespace. -->
56 <xsl:template name="expand_gslib_elements">
57
58
59 <xsl:for-each select="*|text()">
60 <xsl:choose>
61
62
63 <!-- if node has gslib prefix, expand it into appropriate copy-of or call-template element -->
64 <xsl:when test="namespace-uri(.)=namespace::gslib">
65
66 <xsl:variable name="name" select="local-name()"/>
67 <xsl:choose>
68
69 <!-- if library contains a variable of this name, expand to it's value -->
70 <xsl:when test="/skinAndLibraryXsl/libraryXsl//xsl:variable[@name = $name]">
71 <xsl:element name="xsl:copy-of">
72 <xsl:attribute name="select">$<xsl:value-of select="local-name()" /></xsl:attribute>
73 </xsl:element>
74 </xsl:when>
75
76
77 <!-- if library contains a template of this name, expand to a call-template and pass attributes as parameters -->
78 <xsl:otherwise>
79 <xsl:element name="xsl:call-template">
80 <xsl:attribute name="name"> <xsl:value-of select="local-name()" /></xsl:attribute>
81
82 <xsl:for-each select="@*">
83 <xsl:element name="xsl:with-param">
84 <xsl:attribute name="name"><xsl:value-of select="name()"/></xsl:attribute>
85 <xsl:call-template name="convert_attVal_to_valueOf" />
86 </xsl:element>
87 </xsl:for-each>
88 </xsl:element>
89 </xsl:otherwise>
90
91 </xsl:choose>
92 </xsl:when>
93
94 <xsl:when test="self::text()">
95 <xsl:value-of select="."/>
96 </xsl:when>
97
98 <!-- if a regular node v2 -->
99 <xsl:otherwise>
100 <xsl:variable name="element-name" select="name()"/>
101 <xsl:variable name="element-namespace" select="namespace-uri()"/>
102 <xsl:element name="{$element-name}" namespace="{$element-namespace}">
103 <xsl:for-each select="@*">
104 <xsl:variable name="attribute-name" select="name()"/>
105 <xsl:attribute name="{$attribute-name}">
106 <xsl:value-of select="."/>
107 </xsl:attribute>
108 </xsl:for-each>
109 <xsl:call-template name="expand_gslib_elements" />
110 </xsl:element>
111 </xsl:otherwise>
112
113
114 </xsl:choose>
115 </xsl:for-each>
116
117 </xsl:template>
118
119 <!-- converts an attribute value (the current node) into either a literal value or an <xsl:value-of> element -->
120 <xsl:template name="convert_attVal_to_valueOf">
121
122 <xsl:choose>
123 <!-- if attribute is not literal (starts with a "{") -->
124 <xsl:when test="starts-with(string(), '&#123;')">
125 <xsl:element name="xsl:value-of">
126 <xsl:attribute name="disable-output-escaping">yes</xsl:attribute>
127 <xsl:attribute name="select"><xsl:value-of select="substring(string(),2,string-length()-2)"/></xsl:attribute>
128 </xsl:element>
129 </xsl:when>
130 <xsl:otherwise>
131 <xsl:value-of select="."/>
132 </xsl:otherwise>
133 </xsl:choose>
134 </xsl:template>
135
136 <xsl:template name="create_dummy_variables">
137 <xsl:for-each select="//*[namespace-uri()=namespace::gslib]">
138 <xsl:element name="xsl:variable">
139 <xsl:attribute name="name">
140 <xsl:value-of select="local-name()"/>
141 </xsl:attribute>
142 </xsl:element>
143 </xsl:for-each>
144 </xsl:template>
145
146
147</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.