[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: Trevor Nash <tcn@xxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 10:34:57 +0000
stylus span style engineering
Chris wrote:

>The named template approaches were better, though I'm not sure they 
>directly addressed your problem.  Try this:
>
><xsl:template name="test-mark">
>   <xsl:choose>
>     <xsl:when test="@mark">
>       <span style="color:#FF0000">
>         <xsl:apply-templates/>
>       </span>
>     </xsl:when>
>     <xsl:otherwise>
>       <xsl:apply-templates/>
>     </xsl:otherwise>
>   </xsl:choose>
></xsl:template>
>
><xsl:template match="whatever">
>   <xsl:call-template name="test-mark"/>
></xsl:template>
>
>~Chris

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?

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

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

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

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.

Regards,
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


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.