[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
> <!-- 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|