Subject: Re: [xsl] match on attribute anywhere From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 14 Feb 2002 17:28:58 +0000 |
Hi Wendell, > I don't know if that's deeply significant, but it is interesting, > and prompts one to notice a class of problems (namely those where > you need two templates to fire on the same node, one to address one > layer, another to address a layer "on top") that can be addressed > using this feature of xsl:apply-imports. Surprise: it works as > intended. And that class turns out to be broader than just > customizing standard stylesheets. (Like the class of problems > addressed by keys, which is broader than cross-referencing.) True. Though in most of these cases, I find myself using different modes for the different layers. In Andrew's case I'd usually write something like: <xsl:template match="*[@mark]" mode="mark"> <span style="color:#FF0000"> <xsl:apply-templates select="." /> </span> </xsl:template> <xsl:template match="*[not(@mark)]" mode="mark"> <xsl:apply-templates select="." /> </xsl:template> And then a bunch of templates in normal mode for each of the different types of elements, and apply templates in mark mode to add the span element. The trouble with the mode approach is that it's difficult to add layers in the middle. If I wanted a separate layer to make elements with a "flag" attribute larger, I'd have to edit the templates in mark mode so that they applied templates in 'flag' mode instead. With xsl:apply-imports, you'd just add another stylesheet that dealt with the flag attribute, and change the xsl:import in the stylesheet that deals with mark attributes. But the advantages of the mode approach are twofold. Firstly, it keeps everything within a single stylesheet, which I think is beneficial in this case given that there's very little code involved in dealing with each layer. Secondly, it is more flexible because it allows you to choose what nodes to apply templates to explicitly, and allows you to pass parameters to the other templates. (Of course this latter limitation of xsl:apply-imports is a bug in XSLT 1.0, which is going to be fixed in XSLT 2.0.) Hmm... .I wonder whether anyone's ever put several stylesheets, one importing another, in the same physical file (using id attributes to distinguish between them)... 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] match on attribute anywhe, Wendell Piez | Thread | Re: [xsl] match on attribute anywhe, Trevor Nash |
[xsl] differences between fop 0.20 , Bryan Rasmussen | Date | Re: [xsl] sort | uniq via keys, Thomas B. Passin |
Month |