[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: match on attribute anywhere

Subject: Re: match on attribute anywhere
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 14:13:25 +0000
template match with attribute
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"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

...
                
</xsl:stylesheet>

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">
    ...
  </span>
</xsl:template>

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 />
  </span>
</xsl:template>

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.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.