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

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

indented file nicely

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