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

RE: accessing xsl document root from an included styl

Subject: RE: accessing xsl document root from an included stylesheet
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 4 Dec 2009 12:14:10 -0000
RE:  accessing xsl document root from an included  styl
>  <!-- 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 ! 

Try to avoid this construct:

<xsl:variable name="xslmyn">
         <xsl:value-of select="document('')/*/namespace::myn"
/></xsl:variable>

It's both verbose and inefficient compared with the much simpler

<xsl:variable name="xslmyn" select="document('')/*/namespace::myn" />

because if creates a result tree fragment containing a text node, rather
than just a pointer to your existing namespace node.

> 
> 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

Namespaces declared in the stylesheet are scoped to the stylesheet module,
so you really ought to be testing that the namespace is declared correctly
in every module. You can follow the links to included and imported modules
by using document(/*/xsl:include/@href | /*/xsl:include/@href) (which needs
to be done recursively, of course). But there's no way of disovering in an
included module where it was included from.

However, it all seesm very long-winded to me. Why don't you just do

<xsl:template match="/">
  <xsl:if test="not(myn:rootElement)">
     <xsl:message terminate="yes">Root element must be named myn:rootElement
in the correct namespace</xsl:message>


Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

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.