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