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

Last change on this file since 22334 was 22334, checked in by GarthBraithwaite_STG, 9 months ago

view - xslt include apply processing. Tried to add support for HELP element processing but had issues that were not worth the effort and simply noted for now.

File size: 14.5 KB
1<?xml version="1.0" encoding="ISO-8859-1"?>
3<xsl:stylesheet version="3.0" 
4        xmlns:xsl ="" 
5        xmlns:xs  =""
6        xmlns:ibis=""
8        exclude-result-prefixes="ibis xs xsl"
11        <ibis:doc>
12                <name>ibis.include</name>
13                <summary>
14                        Library of generic/common ibis include and copy related apply/match
15                        functions.  Named include instead of ibis-copy as include is the
16                        primary usage.  This code also handles the ibis:href and webapp
17                        prefix type content matches.  Handling within is safe vs other
18                        special match handling.
20                        At one point had a general CONTENT match.  However, this can not
21                        work within an included file because there are some cases where CONTENT
22                        elements need to be handled at different time / more specialized XSLT. 
23                        For example if matching on CONTENT that is within a SELECTION
24                        ibis:include the include match procssing picks it up and removes the
25                        CONTENT element within the selection list so the xslt does not know
26                        about it and can not process the list and content.  For CONTENT to
27                        be processed, specific matches are required.
29                        Some interesting apply options:
30                        xsl:apply-templates select="@* except (@id, @name, @class)"/
31                        xsl:apply-templates select="@id, @name, @class, @* except (@id, @name, @class)"/
32                        xsl:apply-templates select="*, except ELEMENT_X, @* except (@id, @name, @class)"/
34                        GARTH TODO: at some point could have other special ibis: processing
35                        included here for CONTENT type element processing.  The main
36                        HTML_CONTENT has ibis:help, ibis:SelectionsList, ibis:ContentBody etc. 
37                        To be included in the general ibis.copy processing special namespace
38                        processing is needed (see help.xslt and HTMLContentPage.xslt). 
39                        This also makes for loose xsd validation and more complex testing. 
40                </summary>
41        </ibis:doc>
44        <!-- ===================================== M A T C H   C O P Y   M O D E -->
45        <xsl:template match="*" mode="ibis.copy"
46                ibis:doc="Provides the ability to do an apply-templates to a copy-of of
47                        an element (some call this an 'identity transformation').  This
48                        allows for a deep copy with processing (which also allows ibis.include
49                        to be processed)."
50        >
51                <!-- Used the new element and copied the attributes, text, and sub
52                        elements so that any namespace attributes would not be copied.
53                        <xsl:apply-templates select="@*" mode="ibis.copy"/>
54                -->
55                <xsl:element name="{local-name()}">
56                        <xsl:apply-templates select="current()/@* | current()/text() | current()/*"  mode="ibis.copy"/>
57                </xsl:element>
58        </xsl:template>
61        <xsl:template match="text()" mode="ibis.copy" ibis:doc="copies the text.">
62<!-- trims the text - not really needed for wiki - biggest issue with weird text
63        was page indent on and extra line spacing etc.
64                <xsl:value-of select="replace(., '^\s+|\s+$', '')"/>
66                <xsl:value-of select="."/>
67        </xsl:template>
69        <!-- Match Copy Mode was lifted from the page.xslt in 4/2007.  That code has a note
70                about 4-18-06: removed template code and replaced with the mode="ibis.copy"
71                templates above because the namespace was being copied into some HTML elements.
72                See:
73        -->
75        <!-- The following templates are used to help page developers avoid having to
76                hard code the deployment specific context into the URL path of IBIS related
77                web pages.  Example: If the app is deployed into a context called "ibisph-view"
78                and your page is "http://localhost/ibisph-view/about/welcome.html" and it
79                references an image that is under the "webapps/ibisph-view/image" directory
80                it would need a url like "src='/ibisph-view/image/the_image.gif'" to properly
81                get the correct resource.  A relative path of "src='image/the_image.gif'"
82                would cause the browser to request "http://localhost/ibisph-view/about/image/the_image.gif",
83                while a path of "src='/image/the_image.gif'" would request this resource
84                "http://localhost/image/the_image.gif" both of which are wrong.  If the context
85                path is coded so that the resource's URL is explicitly defined then a dependency
86                exists between the web pages and the context which makes the deployment not
87                as portable.  Since the web app context path is needed by the XSLTs to build
88                the correct HTML code it is implemented here to help static page development.
89                Relative links work fine if the resource it within the same directory e.g.
90                if the "about/welcome.html" page contains a relative link to the "about/content_usage.html"
91                page then all is well.  The "about/welcome.html" page can NOT contains a relative
92                link to the "indicator/introduction.html" as it will not find the correct
93                directory.
94        -->
96        <xsl:template match="@*" mode="ibis.copy" ibis:doc="Inner '@*' template that copies the non ibis: namespace attributes">
97                <xsl:copy-of select="."/>
98        </xsl:template>
100        <xsl:template match="@ibis:doc" mode="ibis.copy" ibis:doc="Eats ibis:doc attribute"/>
101        <xsl:template match="ibis:doc"  mode="ibis.copy" ibis:doc="Eats ibis:doc element"/>
104        <!-- Local IBIS URL adjustment templates.  These templates simply add the
105                web application's context path as a prefix to the link reference attribute.
107                NOTE: The remoteRequestPath_ technique could be applied but these are left
108                as is so adopters do not have to redo their content pages - for now...
109GARTH TODO: at some future point convert everything to the more explicit
110ibis:baseRequstPath_  ibis:baseRequstPath_src, ibis:baseRequstPath_href
111        -->
112        <xsl:template match="@ibis:href" mode="ibis.copy" ibis:doc="Inner 'ibis:href' template that adds the 'WebAppURLContextPrefix' to the 'href' attribute.">
113                <xsl:attribute name="href" select="concat($ibis.baseRequestPath, .)"/>
114        </xsl:template>
115        <xsl:template match="@ibis:src" mode="ibis.copy" ibis:doc="Inner 'ibis:src' template that adds the 'WebAppURLContextPrefix' to the 'src' attribute.">
116                <xsl:attribute name="src" select="concat($ibis.baseRequestPath, .)"/>
117        </xsl:template>
118        <xsl:template match="@ibis:action" mode="ibis.copy" ibis:doc="Inner 'ibis:action' template that adds the 'WebAppURLContextPrefix' to the 'action' attribute.">
119                <xsl:attribute name="action" select="concat($ibis.baseRequestPath, .)"/>
120        </xsl:template>
121        <xsl:template match="@ibis:poster" mode="ibis.copy" ibis:doc="Inner 'ibis:poster' template that adds the 'WebAppURLContextPrefix' to the 'poster' attribute.">
122                <xsl:attribute name="poster" select="concat($ibis.baseRequestPath, .)"/>
123        </xsl:template>
125        <xsl:template match="@ibis:*[starts-with(name(), 'ibis:baseRequstPath_')]" mode="ibis.copy" 
126                ibis:doc="Adds the 'WebAppBaseRequestPath' as a prefix to the attribute value with the attribute named the suffix following 'ibis:baseRequstPath_'."
127        >
128                <xsl:attribute name="{substring(name(), 18)}" select="concat($ibis.baseRequestPath, .)"/>
129        </xsl:template>
131        <xsl:template match="ibis:baseRequestPath" mode="ibis.copy" 
132                ibis:doc="Mechanism that allows any ibis.copy processed XML CONTENT to
133                        to get the ibis.baseRequesttPath value.  This is useful for pages
134                        that have javascript that need this value.
135                        Usage: within the CONTENT have an [ibis:baseRequestPath/] element.
136                "
137        >
138                <xsl:value-of select="$ibis.baseRequestPath"/>
139        </xsl:template>
142        <!-- =============================== I B I S   I N C L U D E   M A T C H -->
143        <xsl:template match="ibis:include" mode="#all"
144                ibis:doc="
145                        'ibis:' namespace specific match template which opens and includes
146                        the document via the 'href' attribute and does an 'apply-template'
147                        operation on its contents to process potential sub 'ibis:' matches
148                        and to copy its text, attributes, and processing instructions.  This
149                        is a simple match template that calls the main include template so
150                        that logic is centralized between this general ibis: match and the
151                        ConfigurationIncludeCriteriaExclude's config name ibis: match.
153                        Provides the IBIS-PH system the ability to do simple xinclude type
154                        operations.  As of 6-2004 the xerces parser 2.6.x has xinclude support
155                        but it must be configured when starting the Java JVM or with Java system
156                        properties.  Since this is not a safe option for some deployments (like
157                        Utah's state wide ITS app server) the system wide property solution is not
158                        an option.  To handle being able to deploy into environments where we don't
159                        know which XSL engine is being used this two step xinclude processing
160                        was developed.  This option is not nearly as seamless and requires that
161                        the java controller do 2 transformations - the first being this xinclude
162                        type transformation with the second being the normal desired page type
163                        transformation.  Another option was to do the xinclude template inside the
164                        XSLT as a variable then use that variable for all XML nodes.  This option
165                        appears to be somewhat slow but it is seamless.
167                        See:
168                "
169        >
170                <xsl:call-template name="ibis.include">
171                        <xsl:with-param name="ibisIncludeElement" select="."/>
172                </xsl:call-template>
173        </xsl:template>
176        <xsl:template name="ibis.include"
177                ibis:doc="
178                        Core processing template called when matching an ibis:include.  Opens
179                        the document via the 'href' attribute and does an 'apply-template'
180                        operation on its contents to copy and process content (like sub
181                        'ibis:include' statements and/or other processing instructions).
183                        This code simply copies the contents of the base document and when it
184                        hits the other processing elements like sub ibis:include elements it
185                        matches and recursively calls this template to process...
187                        If a children-only-flag attribute exists in the element then only the
188                        sub elements and child text are included and processed. This is useful
189                        for including an element's text without having to include its root
190                        element or for custom dimension lists for query modules.
192                        child-name-list (with list of delimited values) provides the ability
193                        to limit included elements (like DIMENSION) and any other include
194                        that has the standard NAME element.  This provides a mechanism to
195                        limit child elements to a given name or a CSV or white space delimited
196                        list of names.  This template by definition is limited to including
197                        only child elements so the  children-only-flag is not needed/used.
199                        apply-baseRequestPath causes the doc href to be prefixed with the
200                        ibis.baseRequestPath value.  For normal XSLT views the ibis.baseRequestPath
201                        value IS injected as a parameter into the transformation engine. 
202                        This value is NOT available and thus not injected into the special
203                        query module XSLT include processing (see the notes in the
204                        ConfigurationIncludeCriteriaExclude) so this attribute as of 7/7/2020
205                        can NOT be applied for any QM ibis:includes.
207                        IMPORTANT NOTE:
208                        Prior to 7/7/2020 had various include attribute matching templates
209                        that handled more specialized processing.  However, as things evolved
210                        into more complex functionality that code was moved into this template
211                        so that more explicit processing could be implemented that is easier
212                        to follow and so that it could be called from various include matches 
213                        (like ConfigurationIncludeCriteriaExclude) so that didn't have to
214                        duplicate handling rules.  See that code for some of the attempts to
215                        allow for module matches.
216                "
217        >
218                <xsl:param name="ibisIncludeElement"/>
220                <xsl:variable name="url" select="if(exists($ibisIncludeElement/@apply-baseRequestPath)) then concat($ibis.baseRequestPath, $ibisIncludeElement/@href) else $ibisIncludeElement/@href"/>
221                <xsl:choose>
222                        <xsl:when test="exists($ibisIncludeElement/@child-name-list)">
223                                <xsl:variable name="names" select="tokenize(normalize-space(replace($ibisIncludeElement/@child-name-list, ',', ' ')), '\s+')"/>
224                                <xsl:apply-templates select="document($url)/*/*[NAME=$names]" mode="ibis.copy"/>
225                        </xsl:when>
226                        <xsl:when test="exists($ibisIncludeElement/@children-only-flag)">
227                                <xsl:apply-templates select="document($url, /)/(*/text() | */*)" mode="ibis.copy"/>
228                        </xsl:when>
229                        <xsl:otherwise>
230                                <xsl:apply-templates select="document($url, /)/*" mode="ibis.copy"/>
231                        </xsl:otherwise>
232                </xsl:choose>
233        </xsl:template>
236        <xsl:template match="*" mode="ibis.copyOnlyChildren" ibis:doc="
237                        Matches only contained text and elements.  This is mainly used for
238                        processing CONTENT elements and is the same as calling
239                        ibisIncludeGetContent.  The ibis:include's children-only-flag
240                        provides a similar mechanism but is limited to processing just the
241                        root element of the include file.
242                "
243        >
245GARTH TODO: remove
246<xsl:message select="'ibis.copyOnlyChildren'"/>
247<xsl:message select="current()/(text() | *)"/>
248<xsl:message select="concat('GARTH TOTO:REMOVE THIS MESSAGE.  ibis.copyOnlyChildren.  Container: ', current()/name(), ', Count: ', count(current()//*), ', text: ', current())"/>
250                <xsl:apply-templates select="current()/(text() | *)" mode="ibis.copy"/>
251        </xsl:template>
254        <xsl:template name="ibisIncludeGetContent"
255                ibis:doc="Explicit call to process general CONTENT and returns the
256                        actual text and child elements sans the CONTENT container element
257                        if it exists.  This is potentially safer compared apply
258                        ibis.copyOnlyChildren because of the checking performed.  The apply
259                        mode=ibis.copyOnlyChildren is an easier call when there is a CONTENT
260                        element. 
262                        Tried apply/match of CONTENT but had issues with include processing
263                        handling/removing the CONTENT container element premarturely.  For
264                        example an include that contains SELECTION/CONTENT (which the
265                        selection XLST processes for explicitly later when creating the html). 
266                        When the include processes the file it would match and auto processes
267                        the SELECTION/CONTENT thus removing the CONTENT element from the
268                        parent SELECTION element and thus no longer exists when the SELECTION
269                        element is being processed by the explicit selection XSLT code. 
270                        This would result in problems with mega menu selections that had
271                        CONTENT and was also a problem with help content when being included.
273                        KNOWN VALUE CONTENT ELEMENTS as of 1/2021:
274                        HTML_CONTENT
275                                CONTENT
276                                ibis:ExpandableContent
277                                        CONTENT
278                        SELECTION/SELECTION
279                                CONTENT
280                        HELP
281                                CONTENT
282                "
283        >
284                <xsl:param name="content"/>
286                <xsl:apply-templates 
287                        select="if(exists($content/CONTENT))
288                                then $content/CONTENT/(text() | *)
289                                else $content/(text() | *)"
290                        mode="ibis.copy"
291                />
292        </xsl:template>
296<!-- ============================= End of File ============================= -->
Note: See TracBrowser for help on using the repository browser.