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

Last change on this file since 19890 was 19890, checked in by GarthBraithwaite_STG, 2 years ago

view - TEMP COMMIT. Changed webapp context prefix path to base request path so it is not confused with just the context path. put font icon ref into general. added contextnav css back into layout for topic indexes. css file import ordering tweaks.

File size: 12.1 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>Library of generic/common ibis include related functions</summary>
14        </ibis:doc>
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"/>
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>
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+$', '')"/>
41                <xsl:value-of select="."/>
42        </xsl:template>
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:
48        -->
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        -->
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>
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"/>
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.
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...
84GARTH TODO: at some future point convert everything to the more explicit
85ibis: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>
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>
106        <xsl:template match="ibis:contextPath" mode="ibis.copy" ibis:doc="Mechanism that allows the HTML_CONTENT PAGE type XML content to get the ibis.baseRequesttPath value.  This is useful for pages that have javascript that need this value.">
107                <xsl:value-of select="$ibis.baseRequestPath"/>
108        </xsl:template>
111        <!-- =============================== I B I S   I N C L U D E   M A T C H -->
112        <xsl:template match="ibis:include" mode="#all"
113                ibis:doc="
114                        'ibis:' namespace specific match template which opens
115                        the document via the 'href' attribute and does an 'apply-template'
116                        operation on its contents to process sub 'ibis:include' statements
117                        and to copy its text, attributes, and processing instructions.
119                        Provides the IBISPH system the ability to do simple xinclude
120                        type operations.  As of 6-2004 the xerces parser 2.6.x has xinclude support
121                        but it must be configured when starting the Java JVM or with Java system
122                        properties.  Since this might not be an option for some deployments (like
123                        Utah's state wide ITS app server) the system wide property solution is not
124                        an option.  To handle being able to deploy into environments where we don't
125                        know which XSL engine is being used this two step xinclude processing
126                        was developed.  This option is not nearly as seamless and requires that
127                        the java controller do 2 transformations - the first being this xinclude
128                        type transformation with the second being the normal desired page type
129                        transformation.  Another option was to do the xinclude template inside the
130                        XSLT as a variable then use that variable for all XML nodes.  This option
131                        appears to be somewhat slow but it is seamless.
133                        See:
135                        This page simply copies the contents of the base document and when it
136                        hits the ibis:include element it opens the document with an XSLT document
137                        call based on the href attribute of the xi:include element.  These
138                        elements are then copied into the source document.
140                        NOTE: the included document MUST be a valid XML file e.g. well
141                        formed with a root/master/parent element.
143                        If a children-only-flag attribute exists in the element then only
144                        only the sub elements and child text are included and processed.
145                        This is useful for including an element's text without having to
146                        include its root element.
147                "
148        >
149<!-- this only copies child content - skips container element.
150                <xsl:copy>
151                        <xsl:apply-templates select="document(@href, /)" mode="ibis.include"/>
152                </xsl:copy>
153<xsl:message select="document(@href, /)"/>
154<xsl:message select="concat('FOUND IBIS INCLUDE: ', @href)"/>
156<xsl:message select="@children-only-flag"/>
157<xsl:message select="document(@href, /)
159                <xsl:choose>
160                        <xsl:when test="exists(@include-children-only)">
161                                <xsl:apply-templates select="document(@href, /)/(text() | *)" mode="ibis.copy"/>
162                        </xsl:when>
163                        <xsl:otherwise>
164                                <xsl:apply-templates select="document(@href, /)" mode="ibis.copy"/>
165                        </xsl:otherwise>
166                </xsl:choose>
168OLD CODE:   then document(@href, /)/(text() | *)
169had an issue seen with topic HTML_CONTENT pages including textual blocks with
170child specified.  What happened was that the root container element was copied
171into the doc - not just the children element(s) and text.  So it looked okay but
172was wrong HTML as it contained the XML container element. 
175                <xsl:variable name="url" select="if(0 != string-length(@use-prefix)) then concat($ibis.baseRequestPath, @href) else @href"/>
176                <xsl:apply-templates select=
177                        "if(exists(@children-only-flag))
178                                then document($url, /)/(*/text() | */*)
179                                else document($url, /)
180                        "
181                        mode="ibis.copy"
182                />
183        </xsl:template>
186        <xsl:template match="ibis:include[boolean(@child-name)]" mode="#all"
187                ibis:doc="
188                        Provides the ability to limit includes to a given child element that
189                        has a NAME that matches the supplied child-name attribute. 
190                "
191        >
192<xsl:variable name="url" select="if(0 != string-length(@use-prefix)) then concat($ibis.baseRequestPath, @href) else @href"/>
193<xsl:variable name="childNameElementValue" select="@child-name"/>
194<xsl:message select="concat('********* @child-name: ', $childNameElementValue, ', url: ', $url)"/>
195<xsl:message select="document($url, /)/*/*[NAME=$childNameElementValue]"/>
196<xsl:message select="'*************** END'"/>
198                <xsl:apply-templates select="document($url, /)/*/*[NAME=$childNameElementValue]" mode="ibis.copy"/>
199        </xsl:template>
202        <xsl:template match="ibis:include[boolean(@child-name-list)]" mode="#all"
203                ibis:doc="
204                        Provides the ability to limit includes to a given child element that
205                        has a NAME that matches the supplied child-name attribute. 
206                "
207        >
208                <xsl:variable name="childNames" select="tokenize(normalize-space(replace(@child-name-list, ',', ' ')), '\s+')"/>
209                <xsl:variable name="url" select="if(0 != string-length(@use-prefix)) then concat($ibis.baseRequestPath, @href) else @href"/>
210                <xsl:variable name="doc" select="document($url, /)"/>
211<xsl:message select="concat('********* name: ', name($doc/*), ', url: ', $url)"/>
213                <xsl:if test="not(@children-only-flag)">
214                        <xsl:element name="{name($doc/*)}">
215                                <xsl:apply-templates select="$doc/*/*[NAME=$childNames]" mode="ibis.copy"/>
216                        </xsl:element>
217                </xsl:if>
218                <xsl:if test="boolean(@children-only-flag)">
219                        <xsl:apply-templates select="$doc/*/*[NAME=$childNames]" mode="ibis.copy"/>
220                </xsl:if>
221        </xsl:template>
227<!-- left here for posterity - a way to totally replace an element...
228        <xsl:template match="ibis:a">
229                <xsl:element name="a">
230                        <xsl:attribute name="href"><xsl:value-of select="concat($ibis.baseRequestPath, @href)"/></xsl:attribute>
231                        <xsl:copy-of select="attribute::*[name() != 'href']"/>
232                        <xsl:apply-templates select="current()/text() | current()/*"/>
233                </xsl:element>
234        </xsl:template>
236<!-- img elements do not contain any text or other elements so it doesn't need
237                to process/worry about anything other than it's attributes.
238        <xsl:template match="ibis:img">
239                <img>
240                        <xsl:attribute name="src"><xsl:value-of select="concat($ibis.baseRequestPath, @src)"/></xsl:attribute>
241                        <xsl:copy-of select="attribute::*[name() != 'src']"/>
242                </img>
243        </xsl:template>
245<!-- Since the a element can contain images, divs etc need to process text
246                and elements contained within.
247        <xsl:template match="ibis:form">
248                <xsl:element name="form">
249                        <xsl:attribute name="action"><xsl:value-of select="concat($ibis.baseRequestPath, @action)"/></xsl:attribute>
250                        <xsl:copy-of select="attribute::*[name() != 'action']"/>
251                        <xsl:apply-templates select="current()/text() | current()/*"/>
252                </xsl:element>
253        </xsl:template>
256<!-- ============================= End of File ============================= -->
Note: See TracBrowser for help on using the repository browser.