[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

accessing xsl document root from an included styleshee

Subject: accessing xsl document root from an included stylesheet
From: Jan Bilik <jan.bilik.w@xxxxxxxxx>
Date: Fri, 4 Dec 2009 12:44:54 +0100
 accessing xsl document root from an included styleshee
Hello,

I am using xslt 1.0.

I am managing my own namespace, let's say "http://mynamespace/v1.1",
associated to a stable alias, let's say "myn": In order to access my
XML elements linked to this namespace, I have the following XSL
header:

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
	xmlns:myn="http://mynamespace/v1.1">

When I make changes to my grammar,  I update the version number in my
namespace, in order to avoid running "old" stylesheets onto new XMLs.
Thus, my new XSL header looks like:

 <xsl:stylesheet ...
	xmlns:myn="http://mynamespace/v1.2">


As I want not to process anything if myn versions do not match between
the XSL and the XML being processed, I have added the following code
at the beginning of my stylesheet:

 <!-- Check namespace version -->
 <xsl:template match="/">
	<xsl:variable name="xslmyn"><xsl:value-of
select="document('')/*/namespace::myn" /></xsl:variable>
	<xsl:variable name="matchmyn"><xsl:value-of
select="*/namespace::myn[.=$xslmyn]" /></xsl:variable>
	<xsl:if test="$matchmyn = ''">
		<xsl:message terminate="yes">Mismatch MYN namespace version !!</xsl:message>
	</xsl:if>
	<xsl:apply-templates select="@*|node()"/>
 </xsl:template>

And it works ! If the namespace for the "myn" alias is not the same in
my XSL and my XML, the message is displayed and process is aborted.

Here comes my question : I would like to put the above xsl template in
a separate stylesheet and to include it into each XSL. Alas, by doing
so, the "document('')" (see xmlmyn variable) does no longer match the
main stylesheet root, but the included one:

mynmatch.xsl:
---------
 <?xml version="1.0" encoding="UTF-8"?>

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

 <!-- Check RCD 1.2 namespace version of input XML -->
<xsl:template match="/">
	<xsl:variable name="xslmyn"><xsl:value-of
select="document('')/*/namespace::myn" /></xsl:variable>
	<xsl:variable name="matchmyn"><xsl:value-of
select="*/namespace::myn[.=$xslmyn]" /></xsl:variable>
	<xsl:if test="$matchmyn = ''">
		<xsl:message terminate="yes">Mismatch MYN namespace version !!</xsl:message>
	</xsl:if>
	<xsl:apply-templates select="@*|node()"/>
 </xsl:template>

 </xsl:stylesheet>


mainstylesheet.xsl:
---------
<?xml version="1.0" encoding="UTF-8"?>

 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
	xmlns:myn="http://mynamespace/v1.2">

<xsl:include href="mynmatch.xsl" />

<xsl:output method="text" encoding="UTF-8" />

...


Anybody knows if there is a way to access the xmlns:myn value of
mainstylesheet.xsl from mynmatch.xsl ??

Jan

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.