source: greenstone3/branches/customizingGreenstone3/web/ui/xslt/preProcess.xsl@ 14712

Last change on this file since 14712 was 14712, checked in by dnk2, 17 years ago

dump of existing code

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