1 | <?xml version="1.0" encoding="ISO-8859-1"?> |
---|
2 | |
---|
3 | <xsl:stylesheet version="3.0" |
---|
4 | xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" |
---|
5 | xmlns:xs ="http://www.w3.org/2001/XMLSchema" |
---|
6 | xmlns:ibis="http://www.ibisph.org" |
---|
7 | |
---|
8 | exclude-result-prefixes="ibis xs xsl" |
---|
9 | > |
---|
10 | |
---|
11 | <ibis:doc> |
---|
12 | <name>ibis.include</name> |
---|
13 | <summary>Library of generic/common ibis include related functions</summary> |
---|
14 | </ibis:doc> |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | <!-- ===================================== M A T C H C O P Y M O D E --> |
---|
19 | <xsl:template match="*" mode="ibis.copy" |
---|
20 | ibis:doc="Provides the ability to do an apply-templates to a copy-of of |
---|
21 | an element (some call this an 'identity transformation'). This |
---|
22 | allows for a deep copy with processing (which also allows ibis.include |
---|
23 | to be processed)." |
---|
24 | > |
---|
25 | <!-- Used the new element and copied the attributes, text, and sub |
---|
26 | elements so that any namespace attributes would not be copied. |
---|
27 | <xsl:apply-templates select="@*" mode="ibis.copy"/> |
---|
28 | <xsl:message>IBIS.COPY</xsl:message> |
---|
29 | --> |
---|
30 | <xsl:element name="{local-name()}"> |
---|
31 | <xsl:apply-templates select="current()/@* | current()/text() | current()/*" mode="ibis.copy"/> |
---|
32 | </xsl:element> |
---|
33 | </xsl:template> |
---|
34 | |
---|
35 | |
---|
36 | <xsl:template match="text()" mode="ibis.copy" ibis:doc="copies the text."> |
---|
37 | <!-- trims the text - not really needed for wiki - biggest issue with weird text |
---|
38 | was page indent on and extra line spacing etc. |
---|
39 | <xsl:value-of select="replace(., '^\s+|\s+$', '')"/> |
---|
40 | --> |
---|
41 | <xsl:value-of select="."/> |
---|
42 | </xsl:template> |
---|
43 | |
---|
44 | <!-- Match Copy Mode was lifted from the page.xslt in 4/2007. That code has a note |
---|
45 | about 4-18-06: removed template code and replaced with the mode="ibis.copy" |
---|
46 | templates above because the namespace was being copied into some HTML elements. |
---|
47 | See: http://www.stylusstudio.com/xsllist/200008/post50850.html |
---|
48 | --> |
---|
49 | |
---|
50 | <!-- The following templates are used to help page developers avoid having to |
---|
51 | hard code the deployment specific context into the URL path of IBIS related |
---|
52 | web pages. Example: If the app is deployed into a context called "ibisph-view" |
---|
53 | and your page is "http://localhost/ibisph-view/about/welcome.html" and it |
---|
54 | references an image that is under the "webapps/ibisph-view/image" directory |
---|
55 | it would need a url like "src='/ibisph-view/image/the_image.gif'" to properly |
---|
56 | get the correct resource. A relative path of "src='image/the_image.gif'" |
---|
57 | would cause the browser to request "http://localhost/ibisph-view/about/image/the_image.gif", |
---|
58 | while a path of "src='/image/the_image.gif'" would request this resource |
---|
59 | "http://localhost/image/the_image.gif" both of which are wrong. If the context |
---|
60 | path is coded so that the resource's URL is explicitly defined then a dependency |
---|
61 | exists between the web pages and the context which makes the deployment not |
---|
62 | as portable. Since the web app context path is needed by the XSLTs to build |
---|
63 | the correct HTML code it is implemented here to help static page development. |
---|
64 | Relative links work fine if the resource it within the same directory e.g. |
---|
65 | if the "about/welcome.html" page contains a relative link to the "about/content_usage.html" |
---|
66 | page then all is well. The "about/welcome.html" page can NOT contains a relative |
---|
67 | link to the "indicator/introduction.html" as it will not find the correct |
---|
68 | directory. |
---|
69 | --> |
---|
70 | |
---|
71 | <xsl:template match="@*" mode="ibis.copy" ibis:doc="Inner '@*' template that copies the non ibis: namespace attributes"> |
---|
72 | <xsl:copy-of select="."/> |
---|
73 | </xsl:template> |
---|
74 | |
---|
75 | <xsl:template match="@ibis:doc" mode="ibis.copy" ibis:doc="Eats ibis:doc attribute"/> |
---|
76 | <xsl:template match="ibis:doc" mode="ibis.copy" ibis:doc="Eats ibis:doc element"/> |
---|
77 | |
---|
78 | |
---|
79 | <!-- Local IBIS URL adjustment templates. These templates simply add the |
---|
80 | web application's context path as a prefix to the link reference attribute. |
---|
81 | |
---|
82 | NOTE: The remoteRequestPath_ technique could be applied but these are left |
---|
83 | as is so adopters do not have to redo their content pages - for now... |
---|
84 | GARTH TODO: at some future point convert everything to the more explicit |
---|
85 | ibis:baseRequstPath_ ibis:baseRequstPath_src, ibis:baseRequstPath_href |
---|
86 | --> |
---|
87 | <xsl:template match="@ibis:href" mode="ibis.copy" ibis:doc="Inner 'ibis:href' template that adds the 'WebAppURLContextPrefix' to the 'href' attribute."> |
---|
88 | <xsl:attribute name="href" select="concat($ibis.baseRequestPath, .)"/> |
---|
89 | </xsl:template> |
---|
90 | <xsl:template match="@ibis:src" mode="ibis.copy" ibis:doc="Inner 'ibis:src' template that adds the 'WebAppURLContextPrefix' to the 'src' attribute."> |
---|
91 | <xsl:attribute name="src" select="concat($ibis.baseRequestPath, .)"/> |
---|
92 | </xsl:template> |
---|
93 | <xsl:template match="@ibis:action" mode="ibis.copy" ibis:doc="Inner 'ibis:action' template that adds the 'WebAppURLContextPrefix' to the 'action' attribute."> |
---|
94 | <xsl:attribute name="action" select="concat($ibis.baseRequestPath, .)"/> |
---|
95 | </xsl:template> |
---|
96 | <xsl:template match="@ibis:poster" mode="ibis.copy" ibis:doc="Inner 'ibis:poster' template that adds the 'WebAppURLContextPrefix' to the 'poster' attribute."> |
---|
97 | <xsl:attribute name="poster" select="concat($ibis.baseRequestPath, .)"/> |
---|
98 | </xsl:template> |
---|
99 | |
---|
100 | <xsl:template match="@ibis:*[starts-with(name(), 'ibis:baseRequstPath_')]" mode="ibis.copy" |
---|
101 | ibis:doc="Adds the 'WebAppBaseRequestPath' as a prefix to the attribute value with the attribute named the suffix following 'ibis:baseRequstPath_'." |
---|
102 | > |
---|
103 | <xsl:attribute name="{substring(name(), 18)}" select="concat($ibis.baseRequestPath, .)"/> |
---|
104 | </xsl:template> |
---|
105 | |
---|
106 | <xsl:template match="ibis:baseRequestPath" mode="ibis.copy" |
---|
107 | ibis:doc="Mechanism that allows any ibis.copy processed XML CONTENT to |
---|
108 | to get the ibis.baseRequesttPath value. This is useful for pages |
---|
109 | that have javascript that need this value. |
---|
110 | Usage: within the CONTENT have an [ibis:baseRequestPath/] element. |
---|
111 | " |
---|
112 | > |
---|
113 | <xsl:value-of select="$ibis.baseRequestPath"/> |
---|
114 | </xsl:template> |
---|
115 | |
---|
116 | |
---|
117 | <!-- =============================== I B I S I N C L U D E M A T C H --> |
---|
118 | <xsl:template match="ibis:include" mode="#all" |
---|
119 | ibis:doc=" |
---|
120 | 'ibis:' namespace specific match template which opens |
---|
121 | the document via the 'href' attribute and does an 'apply-template' |
---|
122 | operation on its contents to process sub 'ibis:include' statements |
---|
123 | and to copy its text, attributes, and processing instructions. |
---|
124 | |
---|
125 | Provides the IBISPH system the ability to do simple xinclude |
---|
126 | type operations. As of 6-2004 the xerces parser 2.6.x has xinclude support |
---|
127 | but it must be configured when starting the Java JVM or with Java system |
---|
128 | properties. Since this might not be an option for some deployments (like |
---|
129 | Utah's state wide ITS app server) the system wide property solution is not |
---|
130 | an option. To handle being able to deploy into environments where we don't |
---|
131 | know which XSL engine is being used this two step xinclude processing |
---|
132 | was developed. This option is not nearly as seamless and requires that |
---|
133 | the java controller do 2 transformations - the first being this xinclude |
---|
134 | type transformation with the second being the normal desired page type |
---|
135 | transformation. Another option was to do the xinclude template inside the |
---|
136 | XSLT as a variable then use that variable for all XML nodes. This option |
---|
137 | appears to be somewhat slow but it is seamless. |
---|
138 | |
---|
139 | See: http://www.sagehill.net/docbookxsl/Xinclude.html |
---|
140 | |
---|
141 | This page simply copies the contents of the base document and when it |
---|
142 | hits the ibis:include element it opens the document with an XSLT document |
---|
143 | call based on the href attribute of the xi:include element. These |
---|
144 | elements are then copied into the source document. |
---|
145 | |
---|
146 | NOTE: the included document MUST be a valid XML file e.g. well |
---|
147 | formed with a root/master/parent element. |
---|
148 | |
---|
149 | If a children-only-flag attribute exists in the element then only |
---|
150 | only the sub elements and child text are included and processed. |
---|
151 | This is useful for including an element's text without having to |
---|
152 | include its root element. |
---|
153 | " |
---|
154 | > |
---|
155 | <!-- this only copies child content - skips container element. |
---|
156 | <xsl:copy> |
---|
157 | <xsl:apply-templates select="document(@href, /)" mode="ibis.include"/> |
---|
158 | </xsl:copy> |
---|
159 | <xsl:message select="document(@href, /)"/> |
---|
160 | <xsl:message select="concat('FOUND IBIS INCLUDE: ', @href)"/> |
---|
161 | |
---|
162 | <xsl:message select="@children-only-flag"/> |
---|
163 | <xsl:message select="document(@href, /) |
---|
164 | |
---|
165 | <xsl:choose> |
---|
166 | <xsl:when test="exists(@include-children-only)"> |
---|
167 | <xsl:apply-templates select="document(@href, /)/(text() | *)" mode="ibis.copy"/> |
---|
168 | </xsl:when> |
---|
169 | <xsl:otherwise> |
---|
170 | <xsl:apply-templates select="document(@href, /)" mode="ibis.copy"/> |
---|
171 | </xsl:otherwise> |
---|
172 | </xsl:choose> |
---|
173 | |
---|
174 | OLD CODE: then document(@href, /)/(text() | *) |
---|
175 | had an issue seen with topic HTML_CONTENT pages including textual blocks with |
---|
176 | child specified. What happened was that the root container element was copied |
---|
177 | into the doc - not just the children element(s) and text. So it looked okay but |
---|
178 | was wrong HTML as it contained the XML container element. |
---|
179 | --> |
---|
180 | |
---|
181 | <xsl:variable name="url" select="if(0 != string-length(@use-prefix)) then concat($ibis.baseRequestPath, @href) else @href"/> |
---|
182 | <xsl:apply-templates select= |
---|
183 | "if(exists(@children-only-flag)) |
---|
184 | then document($url, /)/(*/text() | */*) |
---|
185 | else document($url, /) |
---|
186 | " |
---|
187 | mode="ibis.copy" |
---|
188 | /> |
---|
189 | </xsl:template> |
---|
190 | |
---|
191 | |
---|
192 | <xsl:template match="ibis:include[boolean(@child-name)]" mode="#all" |
---|
193 | ibis:doc=" |
---|
194 | Provides the ability to limit includes to a given child element that |
---|
195 | has a NAME that matches the supplied child-name attribute. |
---|
196 | " |
---|
197 | > |
---|
198 | <xsl:variable name="url" select="if(0 != string-length(@use-prefix)) then concat($ibis.baseRequestPath, @href) else @href"/> |
---|
199 | <xsl:variable name="childNameElementValue" select="@child-name"/> |
---|
200 | <xsl:message select="concat('********* @child-name: ', $childNameElementValue, ', url: ', $url)"/> |
---|
201 | <xsl:message select="document($url, /)/*/*[NAME=$childNameElementValue]"/> |
---|
202 | <xsl:message select="'*************** END'"/> |
---|
203 | |
---|
204 | <xsl:apply-templates select="document($url, /)/*/*[NAME=$childNameElementValue]" mode="ibis.copy"/> |
---|
205 | </xsl:template> |
---|
206 | |
---|
207 | |
---|
208 | <xsl:template match="ibis:include[boolean(@child-name-list)]" mode="#all" |
---|
209 | ibis:doc=" |
---|
210 | Provides the ability to limit includes to a given child element that |
---|
211 | has a NAME that matches the supplied child-name attribute. |
---|
212 | " |
---|
213 | > |
---|
214 | <xsl:variable name="childNames" select="tokenize(normalize-space(replace(@child-name-list, ',', ' ')), '\s+')"/> |
---|
215 | <xsl:variable name="url" select="if(0 != string-length(@use-prefix)) then concat($ibis.baseRequestPath, @href) else @href"/> |
---|
216 | <xsl:variable name="doc" select="document($url, /)"/> |
---|
217 | <xsl:message select="concat('********* name: ', name($doc/*), ', url: ', $url)"/> |
---|
218 | |
---|
219 | <xsl:if test="not(@children-only-flag)"> |
---|
220 | <xsl:element name="{name($doc/*)}"> |
---|
221 | <xsl:apply-templates select="$doc/*/*[NAME=$childNames]" mode="ibis.copy"/> |
---|
222 | </xsl:element> |
---|
223 | </xsl:if> |
---|
224 | <xsl:if test="boolean(@children-only-flag)"> |
---|
225 | <xsl:apply-templates select="$doc/*/*[NAME=$childNames]" mode="ibis.copy"/> |
---|
226 | </xsl:if> |
---|
227 | </xsl:template> |
---|
228 | |
---|
229 | </xsl:stylesheet> |
---|
230 | |
---|
231 | |
---|
232 | |
---|
233 | <!-- left here for posterity - a way to totally replace an element... |
---|
234 | <xsl:template match="ibis:a"> |
---|
235 | <xsl:element name="a"> |
---|
236 | <xsl:attribute name="href"><xsl:value-of select="concat($ibis.baseRequestPath, @href)"/></xsl:attribute> |
---|
237 | <xsl:copy-of select="attribute::*[name() != 'href']"/> |
---|
238 | <xsl:apply-templates select="current()/text() | current()/*"/> |
---|
239 | </xsl:element> |
---|
240 | </xsl:template> |
---|
241 | --> |
---|
242 | <!-- img elements do not contain any text or other elements so it doesn't need |
---|
243 | to process/worry about anything other than it's attributes. |
---|
244 | <xsl:template match="ibis:img"> |
---|
245 | <img> |
---|
246 | <xsl:attribute name="src"><xsl:value-of select="concat($ibis.baseRequestPath, @src)"/></xsl:attribute> |
---|
247 | <xsl:copy-of select="attribute::*[name() != 'src']"/> |
---|
248 | </img> |
---|
249 | </xsl:template> |
---|
250 | --> |
---|
251 | <!-- Since the a element can contain images, divs etc need to process text |
---|
252 | and elements contained within. |
---|
253 | <xsl:template match="ibis:form"> |
---|
254 | <xsl:element name="form"> |
---|
255 | <xsl:attribute name="action"><xsl:value-of select="concat($ibis.baseRequestPath, @action)"/></xsl:attribute> |
---|
256 | <xsl:copy-of select="attribute::*[name() != 'action']"/> |
---|
257 | <xsl:apply-templates select="current()/text() | current()/*"/> |
---|
258 | </xsl:element> |
---|
259 | </xsl:template> |
---|
260 | --> |
---|
261 | |
---|
262 | <!-- ============================= End of File ============================= --> |
---|