source: main/trunk/greenstone3/web/interfaces/core/transform/preProcess.xsl@ 28551

Last change on this file since 28551 was 28551, checked in by davidb, 10 years ago

xlink namespace added to keep XSLT-pipeline happy when producing pages that make use of SVG (such as the Salami music collection), which in turn makes use of xlink for its href attributes

File size: 4.5 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:gsvar="http://www.greenstone.org/skinning-var"
7 xmlns:java="http://xml.apache.org/xslt/java"
8 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
9 xmlns:xalan="http://xml.apache.org/xalan"
10 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
11 xmlns:xslt="output.xsl"
12 xmlns:gs3="http://www.greenstone.org/gs3"
13 xmlns:xlink="http://www.w3.org/1999/xlink"
14 >
15
16 <xsl:output method="xml"/>
17 <xsl:namespace-alias
18 stylesheet-prefix="xslt" result-prefix="xsl"/>
19
20 <xsl:template match="/">
21
22 <!-- explicitly output the stylesheet element here so we can include the
23 namespace declarations. They were going missing before with the new xalan/xerces-->
24 <xslt:stylesheet>
25
26 <xsl:for-each select="/skinAndLibraryXsl/skinXsl/xsl:stylesheet">
27
28 <!-- produce an exact copy of skin stylesheet, with gslib nodes expanded. -->
29 <xsl:for-each select="@*">
30 <xsl:variable name="attribute-name" select="name()"/>
31 <xsl:attribute name="{$attribute-name}">
32 <xsl:value-of select="."/>
33 </xsl:attribute>
34 </xsl:for-each>
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 </xsl:for-each>
51 </xslt:stylesheet>
52
53
54 </xsl:template>
55
56
57 <!-- produce an exact copy of the current node, but expand and replace all elements belonging to the gslib/gsvar namespaces. -->
58 <xsl:template name="expand_gslib_elements">
59
60
61 <xsl:for-each select="*|text()">
62 <xsl:choose>
63 <!-- variables -->
64 <xsl:when test="namespace-uri(.)=namespace::gsvar">
65 <xsl:element name="xsl:value-of">
66 <xsl:attribute name="select">$<xsl:value-of select="local-name()" /></xsl:attribute>
67 </xsl:element>
68</xsl:when>
69 <!-- templates -->
70 <xsl:when test="namespace-uri(.)=namespace::gslib">
71 <xsl:variable name="name" select="local-name()"/>
72 <xsl:element name="xsl:call-template">
73 <xsl:attribute name="name"> <xsl:value-of select="local-name()" /></xsl:attribute>
74
75 <xsl:for-each select="@*">
76 <xsl:element name="xsl:with-param">
77 <xsl:attribute name="name"><xsl:value-of select="name()"/></xsl:attribute>
78 <xsl:call-template name="convert_attVal_to_valueOf" />
79 </xsl:element>
80 </xsl:for-each>
81 </xsl:element>
82 </xsl:when>
83
84 <xsl:when test="self::text()">
85 <xsl:value-of select="."/>
86 </xsl:when>
87
88 <!-- if a regular node v2 -->
89 <xsl:otherwise>
90 <xsl:variable name="element-name" select="name()"/>
91 <xsl:variable name="element-namespace" select="namespace-uri()"/>
92 <xsl:element name="{$element-name}" namespace="{$element-namespace}">
93 <xsl:for-each select="@*">
94 <xsl:variable name="attribute-name" select="name()"/>
95 <xsl:attribute name="{$attribute-name}">
96 <xsl:value-of select="."/>
97 </xsl:attribute>
98 </xsl:for-each>
99 <xsl:call-template name="expand_gslib_elements" />
100 </xsl:element>
101 </xsl:otherwise>
102
103
104 </xsl:choose>
105 </xsl:for-each>
106
107 </xsl:template>
108
109 <!-- converts an attribute value (the current node) into either a literal value or an <xsl:value-of> element -->
110 <xsl:template name="convert_attVal_to_valueOf">
111
112 <xsl:choose>
113 <!-- if attribute is not literal (starts with a "{") -->
114 <xsl:when test="starts-with(string(), '&#123;')">
115 <xsl:element name="xsl:value-of">
116 <xsl:attribute name="disable-output-escaping">yes</xsl:attribute>
117 <xsl:attribute name="select"><xsl:value-of select="substring(string(),2,string-length()-2)"/></xsl:attribute>
118 </xsl:element>
119 </xsl:when>
120 <xsl:otherwise>
121 <xsl:value-of select="."/>
122 </xsl:otherwise>
123 </xsl:choose>
124 </xsl:template>
125
126 <xsl:template name="create_dummy_variables">
127 <xsl:for-each select="//*[namespace-uri()=namespace::gslib]">
128 <xsl:element name="xsl:variable">
129 <xsl:attribute name="name">
130 <xsl:value-of select="local-name()"/>
131 </xsl:attribute>
132 </xsl:element>
133 </xsl:for-each>
134 </xsl:template>
135
136
137</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.