RE: [xsl] match on attribute anywhere

Subject: RE: [xsl] match on attribute anywhere
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 14:45:24 -0000

Absolutely brilliant.  I know you get a lot of (fully justified) praise on
this list, but I reackon youve excelled yourself this time :)

nice one



-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Jeni Tennison
Sent: Thursday, February 14, 2002 2:13 PM
To: Andrew Welch
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] match on attribute anywhere

Hi Andrew,

> However, if you have several templates and the knowledge that @mark
> could appear on any element, it wouldnt be so easy. It would be
> great to add just one extra template to match @mark anywhere, and
> highlight its contents.

Actually, this is a situation xsl:apply-imports can actually be useful!

Have your general templates, each dealing with individual nodes in one
stylesheet (I'll call it base.xsl).

Then create another stylesheet that *imports* that base stylesheet:

<xsl:stylesheet version="1.0"

<xsl:import href="base.xsl" />



Within that stylesheet, create a template that matches elements with
mark attributes, which creates the span element that you're after:

<xsl:template match="*[@mark]">
  <span style="color:#FF0000">

For the content of the span element, you want to use the template
in the base.xsl stylesheet for whatever element it is has been matched
by this template. This is exactly what the xsl:apply-imports
instruction allows you to do. If you add:

<xsl:template match="*[@mark]">
  <span style="color:#FF0000">
    <xsl:apply-imports />

The processor will take the current node (the element with the mark
attribute) and look in the imported stylesheets (just base.xsl in this
example) for a template that matches that node. The result of that
template becomes the content of the span element.

If an element doesn't have a mark attribute, then the processor just
uses the imported template anyway.



Jeni Tennison

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread