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 | >
|
---|
14 |
|
---|
15 | <xsl:output method="xml"/>
|
---|
16 | <xsl:namespace-alias
|
---|
17 | stylesheet-prefix="xslt" result-prefix="xsl"/>
|
---|
18 |
|
---|
19 | <xsl:template match="/">
|
---|
20 |
|
---|
21 | <!-- explicitly output the stylesheet element here so we can include the
|
---|
22 | namespace declarations. They were going missing before with the new xalan/xerces-->
|
---|
23 | <xslt:stylesheet>
|
---|
24 |
|
---|
25 | <xsl:for-each select="/skinAndLibraryXsl/skinXsl/xsl:stylesheet">
|
---|
26 |
|
---|
27 | <!-- produce an exact copy of skin stylesheet, with gslib nodes expanded. -->
|
---|
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 | <!-- merge the attributes of the library stylesheet -->
|
---|
35 | <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet/@*">
|
---|
36 | <xsl:variable name="attribute-name" select="name()"/>
|
---|
37 | <xsl:attribute name="{$attribute-name}">
|
---|
38 | <xsl:value-of select="."/>
|
---|
39 | </xsl:attribute>
|
---|
40 | </xsl:for-each>
|
---|
41 |
|
---|
42 | <xsl:call-template name="expand_gslib_elements" />
|
---|
43 |
|
---|
44 | <!-- add content of library to the skin stylesheet -->
|
---|
45 | <xsl:for-each select="/skinAndLibraryXsl/libraryXsl/xsl:stylesheet">
|
---|
46 | <xsl:call-template name="expand_gslib_elements" />
|
---|
47 | </xsl:for-each>
|
---|
48 |
|
---|
49 | </xsl:for-each>
|
---|
50 | </xslt:stylesheet>
|
---|
51 |
|
---|
52 |
|
---|
53 | </xsl:template>
|
---|
54 |
|
---|
55 |
|
---|
56 | <!-- produce an exact copy of the current node, but expand and replace all elements belonging to the gslib/gsvar namespaces. -->
|
---|
57 | <xsl:template name="expand_gslib_elements">
|
---|
58 |
|
---|
59 |
|
---|
60 | <xsl:for-each select="*|text()">
|
---|
61 | <xsl:choose>
|
---|
62 | <!-- variables -->
|
---|
63 | <xsl:when test="namespace-uri(.)=namespace::gsvar">
|
---|
64 | <xsl:element name="xsl:value-of">
|
---|
65 | <xsl:attribute name="select">$<xsl:value-of select="local-name()" /></xsl:attribute>
|
---|
66 | </xsl:element>
|
---|
67 | </xsl:when>
|
---|
68 | <!-- templates -->
|
---|
69 | <xsl:when test="namespace-uri(.)=namespace::gslib">
|
---|
70 | <xsl:variable name="name" select="local-name()"/>
|
---|
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:when>
|
---|
82 |
|
---|
83 | <xsl:when test="self::text()">
|
---|
84 | <xsl:value-of select="."/>
|
---|
85 | </xsl:when>
|
---|
86 |
|
---|
87 | <!-- if a regular node v2 -->
|
---|
88 | <xsl:otherwise>
|
---|
89 | <xsl:variable name="element-name" select="name()"/>
|
---|
90 | <xsl:variable name="element-namespace" select="namespace-uri()"/>
|
---|
91 | <xsl:element name="{$element-name}" namespace="{$element-namespace}">
|
---|
92 | <xsl:for-each select="@*">
|
---|
93 | <xsl:variable name="attribute-name" select="name()"/>
|
---|
94 | <xsl:attribute name="{$attribute-name}">
|
---|
95 | <xsl:value-of select="."/>
|
---|
96 | </xsl:attribute>
|
---|
97 | </xsl:for-each>
|
---|
98 | <xsl:call-template name="expand_gslib_elements" />
|
---|
99 | </xsl:element>
|
---|
100 | </xsl:otherwise>
|
---|
101 |
|
---|
102 |
|
---|
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(), '{')">
|
---|
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>
|
---|