source: main/trunk/ibisph-view/src/main/webapp/xslt/_ibis-include.xslt @ 20976

Last change on this file since 20976 was 20976, checked in by GarthBraithwaite_STG, 2 months ago

view - TEMP ibis:include commit to capture include processing tries. Secure query SS to set the related base path.

File size: 10.4 KB
Line 
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                -->
29                <xsl:element name="{local-name()}">
30                        <xsl:apply-templates select="current()/@* | current()/text() | current()/*"  mode="ibis.copy"/>
31                </xsl:element>
32        </xsl:template>
33
34
35        <xsl:template match="text()" mode="ibis.copy" ibis:doc="copies the text.">
36<!-- trims the text - not really needed for wiki - biggest issue with weird text
37        was page indent on and extra line spacing etc.
38                <xsl:value-of select="replace(., '^\s+|\s+$', '')"/>
39-->
40                <xsl:value-of select="."/>
41        </xsl:template>
42
43        <!-- Match Copy Mode was lifted from the page.xslt in 4/2007.  That code has a note
44                about 4-18-06: removed template code and replaced with the mode="ibis.copy"
45                templates above because the namespace was being copied into some HTML elements.
46                See: http://www.stylusstudio.com/xsllist/200008/post50850.html
47        -->
48
49        <!-- The following templates are used to help page developers avoid having to
50                hard code the deployment specific context into the URL path of IBIS related
51                web pages.  Example: If the app is deployed into a context called "ibisph-view"
52                and your page is "http://localhost/ibisph-view/about/welcome.html" and it
53                references an image that is under the "webapps/ibisph-view/image" directory
54                it would need a url like "src='/ibisph-view/image/the_image.gif'" to properly
55                get the correct resource.  A relative path of "src='image/the_image.gif'"
56                would cause the browser to request "http://localhost/ibisph-view/about/image/the_image.gif",
57                while a path of "src='/image/the_image.gif'" would request this resource
58                "http://localhost/image/the_image.gif" both of which are wrong.  If the context
59                path is coded so that the resource's URL is explicitly defined then a dependency
60                exists between the web pages and the context which makes the deployment not
61                as portable.  Since the web app context path is needed by the XSLTs to build
62                the correct HTML code it is implemented here to help static page development.
63                Relative links work fine if the resource it within the same directory e.g.
64                if the "about/welcome.html" page contains a relative link to the "about/content_usage.html"
65                page then all is well.  The "about/welcome.html" page can NOT contains a relative
66                link to the "indicator/introduction.html" as it will not find the correct
67                directory.
68        -->
69
70        <xsl:template match="@*" mode="ibis.copy" ibis:doc="Inner '@*' template that copies the non ibis: namespace attributes">
71                <xsl:copy-of select="."/>
72        </xsl:template>
73
74        <xsl:template match="@ibis:doc" mode="ibis.copy" ibis:doc="Eats ibis:doc attribute"/>
75        <xsl:template match="ibis:doc"  mode="ibis.copy" ibis:doc="Eats ibis:doc element"/>
76
77
78        <!-- Local IBIS URL adjustment templates.  These templates simply add the
79                web application's context path as a prefix to the link reference attribute.
80
81                NOTE: The remoteRequestPath_ technique could be applied but these are left
82                as is so adopters do not have to redo their content pages - for now...
83GARTH TODO: at some future point convert everything to the more explicit
84ibis:baseRequstPath_  ibis:baseRequstPath_src, ibis:baseRequstPath_href
85        -->
86        <xsl:template match="@ibis:href" mode="ibis.copy" ibis:doc="Inner 'ibis:href' template that adds the 'WebAppURLContextPrefix' to the 'href' attribute.">
87                <xsl:attribute name="href" select="concat($ibis.baseRequestPath, .)"/>
88        </xsl:template>
89        <xsl:template match="@ibis:src" mode="ibis.copy" ibis:doc="Inner 'ibis:src' template that adds the 'WebAppURLContextPrefix' to the 'src' attribute.">
90                <xsl:attribute name="src" select="concat($ibis.baseRequestPath, .)"/>
91        </xsl:template>
92        <xsl:template match="@ibis:action" mode="ibis.copy" ibis:doc="Inner 'ibis:action' template that adds the 'WebAppURLContextPrefix' to the 'action' attribute.">
93                <xsl:attribute name="action" select="concat($ibis.baseRequestPath, .)"/>
94        </xsl:template>
95        <xsl:template match="@ibis:poster" mode="ibis.copy" ibis:doc="Inner 'ibis:poster' template that adds the 'WebAppURLContextPrefix' to the 'poster' attribute.">
96                <xsl:attribute name="poster" select="concat($ibis.baseRequestPath, .)"/>
97        </xsl:template>
98
99        <xsl:template match="@ibis:*[starts-with(name(), 'ibis:baseRequstPath_')]" mode="ibis.copy" 
100                ibis:doc="Adds the 'WebAppBaseRequestPath' as a prefix to the attribute value with the attribute named the suffix following 'ibis:baseRequstPath_'."
101        >
102                <xsl:attribute name="{substring(name(), 18)}" select="concat($ibis.baseRequestPath, .)"/>
103        </xsl:template>
104
105        <xsl:template match="ibis:baseRequestPath" mode="ibis.copy" 
106                ibis:doc="Mechanism that allows any ibis.copy processed XML CONTENT to
107                        to get the ibis.baseRequesttPath value.  This is useful for pages
108                        that have javascript that need this value.
109                        Usage: within the CONTENT have an [ibis:baseRequestPath/] element.
110                "
111        >
112                <xsl:value-of select="$ibis.baseRequestPath"/>
113        </xsl:template>
114
115
116        <!-- =============================== I B I S   I N C L U D E   M A T C H -->
117        <xsl:template match="ibis:include" mode="#all"
118                ibis:doc="
119                        'ibis:' namespace specific match template which opens
120                        the document via the 'href' attribute and does an 'apply-template'
121                        operation on its contents to process sub 'ibis:include' statements
122                        and to copy its text, attributes, and processing instructions.
123
124                        Provides the IBISPH system the ability to do simple xinclude type
125                        operations.  As of 6-2004 the xerces parser 2.6.x has xinclude support
126                        but it must be configured when starting the Java JVM or with Java system
127                        properties.  Since this might not be an option for some deployments (like
128                        Utah's state wide ITS app server) the system wide property solution is not
129                        an option.  To handle being able to deploy into environments where we don't
130                        know which XSL engine is being used this two step xinclude processing
131                        was developed.  This option is not nearly as seamless and requires that
132                        the java controller do 2 transformations - the first being this xinclude
133                        type transformation with the second being the normal desired page type
134                        transformation.  Another option was to do the xinclude template inside the
135                        XSLT as a variable then use that variable for all XML nodes.  This option
136                        appears to be somewhat slow but it is seamless.
137
138                        See: http://www.sagehill.net/docbookxsl/Xinclude.html
139
140                        This page simply copies the contents of the base document and when it
141                        hits the ibis:include element it opens the document with an XSLT document
142                        call based on the href attribute of the xi:include element.  These
143                        elements are then copied into the source document.
144
145                        NOTE: the included document MUST be a valid XML file e.g. well
146                        formed with a root/master/parent element.
147
148                        If a children-only-flag attribute exists in the element then only the
149                        sub elements and child text are included and processed. This is useful
150                        for including an element's text without having to include its root
151                        element or for custom dimension lists for query modules.
152                "
153        >
154                <xsl:variable name="url" select="if(0 != string-length(@use-prefix)) then concat($ibis.baseRequestPath, @href) else @href"/>
155                <xsl:apply-templates select=
156                        "if(exists(@children-only-flag))
157                                then document($url, /)/(*/text() | */*)
158                                else document($url, /)
159                        "
160                        mode="ibis.copy"
161                />
162        </xsl:template>
163
164
165        <xsl:template match="ibis:include[boolean(@child-name-list)]" mode="#all"
166                ibis:doc="
167                        Provides the ability to limit included DIMENSION and any other include
168                        that has the standard NAME element.  This provides a mechanism to
169                        limit child elements to a given name or a CSV or white space delimited
170                        list of names.  See the ibis:include function for more info about
171                        this template mechanism works.
172
173                        This template should only be implemented for child elements that
174                        contain a sub NAME element.
175                "
176        >
177                <xsl:variable name="names"       select="tokenize(normalize-space(replace(@child-name-list, ',', ' ')), '\s+')"/>
178                <xsl:variable name="rootElement" select="document(@href)/*"/>
179
180<xsl:message select="concat('in NEW child name list, href=', @href, ', Count of elements: ', count($rootElement/*), ', ibis.baseRequestPath: ', $ibis.baseRequestPath)"/>
181<xsl:message select="."/>
182                <xsl:for-each select="$names">
183<xsl:message select="."/>
184                        <xsl:apply-templates select="$rootElement/*[NAME=current()]" mode="ibis.copy"/>
185                </xsl:for-each>
186        </xsl:template>
187
188
189
190        <xsl:template match="ibis:xxxxxxxinclude[boolean(@child-name-list)]" mode="#all"
191                ibis:doc="
192                        Provides the ability to limit included DIMENSION and any other include
193                        that has the standard child NAME element.  This provides a mechanism to
194                        limit child elements to a given name or a CSV or white space delimited
195                        list of names.  By definition this include already handles the child
196                        only inclusions so no special include processing is done for this. 
197                        Also the special QM config name list processing is handled in specific
198                        QM XSLT XML code.  See the ibis:include function for more info about
199                        how the ibis:include mechanism works.
200                "
201        >
202                <xsl:variable name="names"       select="tokenize(normalize-space(replace(@child-name-list, ',', ' ')), '\s+')"/>
203                <xsl:variable name="rootElement" select="document(@href, /)"/>
204
205                <xsl:for-each select="$names">
206<xsl:message select="."/>
207<xsl:message select="$rootElement/*"/>
208                        <xsl:apply-templates select="$rootElement/*[NAME=current()]" mode="ibis.copy"/>
209                </xsl:for-each>
210        </xsl:template>
211
212</xsl:stylesheet>
213<!-- ============================= End of File ============================= -->
Note: See TracBrowser for help on using the repository browser.