[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: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 13:48:03 -0000
patterm marking
>I thought the point of the question was that there were several
>'whatever-else'-s, each with *specific* processing except for the one
>common bit: whatever was to be generated should be wrapped in a 'span'
>to change the colour if @mark='1' was present.  Andrew?

Sure.  Take this piece of xml:


You could write some templates to display this.  Then, say, someone added

  <c mark='1'>world</c>

and told you that any element with @mark should be highlighted.  This is
fine for this example, as you could just modify the template for <c>.
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.

Trevor's solution works well here, although I must admit I have only tested
it on a small amount of data.  It will however be used in the next release
when I can finally get away from wd-xsl ;)

Thanks for the suggestions



If I am right, here is a tidier version of my first attempt:

For each element type or patterm 'x' write:

<!-- add a mode to the template you already have -->
<xsl:template match="x" mode="process">
    do whatever for element type 'x', including possibly
    xsl:apply-templates *without* a mode.

 To do the marking add:

<!-- pick up any elements with a mark attribute -->
<xsl:template match="*[@mark='1']" priority="2">
    <span style="color:#FF0000">
                  <!-- go back and do the standard thing, using
                         a different mode so that you do
                         not recursively trigger this template -->
 	<xsl:apply-templates select="." mode="process" />

<!-- and the others -->
<xsl:template match="*">
 	<xsl:apply-templates select="." mode="process" />

Though this version is easier to maintain (you don't have to have that
extra match+call for every template), its probably slower - it does a
template select twice for every node, where the original only did a
double select for marked nodes.  But then it had roughly twice as many
templates to look at, so it could go either way.

Trevor Nash

Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271
email:     tcn@xxxxxxxxxxxxx

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

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

Current Thread


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.
First Name
Last Name
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.