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

Last change on this file since 16449 was 16373, checked in by davidb, 16 years ago

Renaming of file to case-sensitive version. Original commit from Windows seems to have lost the uppercase letters

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