[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] Reliance on import precedence considered dangerous
Subject: [xsl] Reliance on import precedence considered dangerous From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Fri, 16 Feb 2001 10:25:12 +0000 |
I think I've discovered an odd behaviour concerning imported stylesheets that I haven't seen mentioned anywhere. I'd be very glad to be proved wrong (on both it's factual or it's status as a known problem that David first identified 18 months ago). When you import the same utility stylesheet (D) into two stylesheets (B and C) that you then import into a main stylesheet (A), any templates, attribute sets, global variables or parameters (and so on for a few other things) in the first stylesheet that's imported (B) that override the ones in the utility stylesheet (D) will no longer work as they would if the stylesheet (B) were run standalone. Here is an illustrative example. In preparation for XSLT UK, I'm putting together a list of hostelries that may be good locations for vehement arguments on the use of xsl:script. I have a neat little utility function that uses the Piez Technique to output the rating of a hostelry as a number of *s: <xsl:template match="city[name = 'Oxford']/hostelry" mode="rating"> <xsl:for-each select="$loadsanodes[position() <= @rating]"> <xsl:text>*</xsl:text> </xsl:for-each> </xsl:template> and this I have placed in a utility stylesheet unimaginatively called 'utilities.xsl'. I then have two stylesheets that can stand alone if necessary. One called 'pubs.xsl' and one called 'restaurants.xsl'. These create tables of the pubs and restaurants, including their rating. In honour of David Carlisle's penchant for OP, there's a special template of pubs.xsl that overrides the one above: <xsl:template match="city[name = 'Oxford']/ hostelry[drink = 'Old Peculier']" mode="rating"> <xsl:for-each select="$loadsanodes[position() <= @rating]"> <xsl:text>D</xsl:text> </xsl:for-each> </xsl:template> pubs.xsl works hunkydory on its own - good places to get David that pint you owe him are labelled appropriately. However, when I import both pubs.xsl and restaurant.xsl into my main stylesheet: <xsl:import href="pubs.xsl" /> <xsl:import href="restaurant.xsl" /> Suddenly they stop being labelled! Why? Well, looking at the import tree, utilities.xsl imported by restaurant.xsl has a higher import precedence than pubs.xsl. Since the two templates have the same priority, the one with the highest import precedence wins - the one in utilities.xsl. To make it work I have to add an explicit priority to the template in pubs.xsl. If this is the case, perhaps it is something that should be added in a Note in Section 2.6.2 of the XSLT 1.1 WD? It's not error-producing like the equivalent with xsl:include, but it might be unexpected. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] W3 XSLT 2.0 Requirements , Francis Norton | Thread | Re: [xsl] Reliance on import preced, David Carlisle |
Re: [xsl] choose an "artificial" ro, David Carlisle | Date | Re: [xsl] French Book and Front Sof, Samuzeau Pascal |
Month |
Keywords