Subject: RE: [xsl] How to use multiple xsl:import From: Pieter Reint Siegers Kort <pieter.siegers@xxxxxxxxxxx> Date: Wed, 6 Apr 2005 10:30:29 -0500 |
Thanx Michael and Dimitre. I understand that using mode will help me control the way the processor chooses a template. Michael already pointed that out (both here and in his book) and you clarified it. Maybe I stated the question wrong. Actually we're not referring to the import precedence. We're trying to find a way to name the imported stylesheets, and apply them **anywhere** we choose in the web page. For that, there's no functionality in xsl:import, AFAIK. Since xsl:import doesn't provide this functionality (it is only allowed as a top element, and it lacks a name or mode attribute), it means we simply cannot use the approach my collegue had in mind. But there's another approach. Back in March 2002 I ported a clasical ASP aplication to using modular approach, using the xsl:include approach. That would be a better solution, although we'll loose the import precedence functionality. Following is the mother template where six includes are called. <?xml version='1.0' ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt" version="1.0"> <xsl:output method="html" indent="yes" omit-xml-declaration="yes" encoding="Windows-1252" /> <xsl:include href="nace6inc1.xsl" /> <xsl:include href="nace6inc2.xsl" /> <xsl:include href="nace6inc3sub1.xsl" /> <xsl:include href="nace6inc3sub2.xsl" /> <xsl:include href="nace6inc3sub3.xsl" /> <xsl:include href="nace6inc4.xsl" /> <xsl:template match="/"> <xsl:apply-templates select="root" /> </xsl:template> <xsl:template name="root" match="root"> <html> <head> <title>E L N O R T E - nota</title> <link href="img/StyleSheet.css" type="text/css" rel="STYLESHEET" /> </head> <body vlink="#000080" alink="#000080" link="#000080" bgcolor="#ffffff" leftmargin="0" topmargin="0" marginheight="?0?" marginwidth="?0?"> <!-- Header Terra --> <xsl:call-template name="headerTerra" /> <!-- Header Elnorte --> <xsl:call-template name="headerElnorte" /> <table cellspacing="0" cellpadding="0" width="760" border="0"> <tbody> <tr> <!-- Parte Izquierda - Navegacion--> <xsl:call-template name="navbarElnorte" /> <!-- Parte Central --> <xsl:call-template name="centralElnorte" /> <!-- Parte Derecha -Herramientas--> <xsl:call-template name="herrElnorte" /> </tr> </tbody> </table> <!-- Parte Derecha -Herramientas--> <xsl:call-template name="footerElnorte" /> </body> </html> </xsl:template> </xsl:stylesheet> Thanx again for the help, I appreciate it a lot! Cheers, <prs/> -----Original Message----- From: Dimitre Novatchev [mailto:dnovatchev@xxxxxxxxx] Sent: Wednesday, April 06, 2005 6:19 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] How to use multiple xsl:import On Apr 6, 2005 9:50 AM, Pieter Reint Siegers Kort <pieter.siegers@xxxxxxxxxxx> wrote: > > Since the two xsl:apply-imports are in the same template, they will > > follow > exactly the same search path in looking for the next template to apply. > > This makes sense. > > > If you want to search different sets of templates in the two cases, > > the > mechanism to use is modes. > > This not... how do I use mode on xsl:import? AFAIK mode belongs to > xsl:template and xsl:call-templates... please explain! This makes perfect sense. Let's take an example: If the imported stylesheet contains a template, which matches an element named "foo" and the importing stylesheet contains a template matching node(), at the instruction: <xsl:apply-templates select="foo"/> the template from the importing stylesheet will always be selected over the one from the imported stylesheet as the former has a higher import precedence. The only way to ensure that the wanted template from the imported stylesheet will be selected is to specify it with a unique mode and change the xsl:apply-templates to: <xsl:apply-templates select="foo" mode="fooprefix:fooMode"/> where fooprefix is bound to a unique namespace-uri Often the author of a stylesheet that will be imported doesn't know what stylesheets will be importing it. The only sound protection from a template with higher imort precedence being selected instead of owr own is to provide it with unique mode. In FXSL there is a general convention that referenced templates (whose template references are passed as parameters to other templates/functions) must have: mode="f:FXSL" where "f" is bound to "http://www.sf.net/fxsl" The templates that are passed such parameters initiate the referenced templates using: <xsl:apply-templates mode="f:FXSL"/> Of course, this is incompatible with the idea of xsl:apply-imports and, it turns out, the idea of xsl:apply-imports is not a bulletproof one. See for example: "Reliance on import precedence considered dangerous " by Jeni Tennison at: http://www.xslt.com/html/xsl-list/2001-02/msg00613.html Hope this helped. Cheers, Dimitre Novatchev.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to use multiple xsl:i, Dimitre Novatchev | Thread | Re: [xsl] How to use multiple xsl:i, David Carlisle |
RE: [xsl] XSLT for usable yet valid, Kevin Rodgers | Date | Re: [xsl] How to use multiple xsl:i, David Carlisle |
Month |