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

Last change on this file since 18544 was 18544, checked in by max, 15 years ago

Fixed to problem that used to mess the extracted GSF statements (xslt namespace) when extracting the GSLib statements. Now when we are rewriting a regular node, we take care of its original namespace.

File size: 4.6 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2
3<xsl:stylesheet version="1.0"
4xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
5xmlns:gslib="http://www.greenstone.org/skinning"
6xmlns:java="http://xml.apache.org/xslt/java"
7xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
8xmlns:xalan="http://xml.apache.org/xalan"
9xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10xmlns: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 v2 -->
102 <xsl:otherwise>
103 <xsl:variable name="element-name" select="name()"/>
104 <xsl:variable name="element-namespace" select="namespace-uri()"/>
105 <xsl:element name="{$element-name}" namespace="{$element-namespace}">
106 <xsl:for-each select="@*">
107 <xsl:variable name="attribute-name" select="name()"/>
108 <xsl:attribute name="{$attribute-name}">
109 <xsl:value-of select="."/>
110 </xsl:attribute>
111 </xsl:for-each>
112 <xsl:call-template name="expand_gslib_elements" />
113 </xsl:element>
114 </xsl:otherwise>
115
116
117 </xsl:choose>
118 </xsl:for-each>
119
120</xsl:template>
121
122<!-- converts an attribute value (the current node) into either a literal value or an <xsl:value-of> element -->
123<xsl:template name="convert_attVal_to_valueOf">
124
125 <xsl:choose>
126 <!-- if attribute is not literal (starts with a "{") -->
127 <xsl:when test="starts-with(string(), '&#123;')">
128 <xsl:element name="xsl:value-of">
129 <xsl:attribute name="disable-output-escaping">yes</xsl:attribute>
130 <xsl:attribute name="select"><xsl:value-of select="substring(string(),2,string-length()-2)"/></xsl:attribute>
131 </xsl:element>
132 </xsl:when>
133 <xsl:otherwise>
134 <xsl:value-of select="."/>
135 </xsl:otherwise>
136 </xsl:choose>
137</xsl:template>
138
139<xsl:template name="create_dummy_variables">
140 <xsl:for-each select="//*[namespace-uri()=namespace::gslib]">
141 <xsl:element name="xsl:variable">
142 <xsl:attribute name="name">
143 <xsl:value-of select="local-name()"/>
144 </xsl:attribute>
145 </xsl:element>
146 </xsl:for-each>
147</xsl:template>
148
149
150</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.