This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: match on attribute anywhere
- From: "Christopher R. Maden" <crism at maden dot org>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 13 Feb 2002 16:38:09 -0800
- Subject: Re: [xsl] match on attribute anywhere
- References: <200202130911.g1D9B1L26683@mail.informatik.hu-berlin.de>
- Reply-to: xsl-list at lists dot mulberrytech dot com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 02:19 13-02-2002, Andrew Welch wrote:
>In my xml, if an element has an attribute 'mark=1' then it should be
>highlighted. I can achieve it by putting a test on each template:
>
>However, doing this for each template seems a bit overkill, I would like to
>specify a general template like this:
>
><xsl:template match="@mark">
> <span style="color:#FF0000">
> <xsl:apply-templates select/>
> </span>
></xsl:template>
>
>and apply it using:
>
><xsl:apply-templates select="@mark|node()"/>
>
>This currently doesnt work for me - is it the correct approach?
First, you can't do <xsl:apply-templates select/>; in XML, you must have a
name and value for an attribute. But even if you did <xsl:apply-templates
select="."/>, you'd be applying templates to the value of the mark
attribute, not to the content of the element that had the mark attribute.
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
- --
Christopher R. Maden, Principal Consultant, HMM Consulting Int'l, Inc.
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://www.hmmci.com/ > <URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4 5DFC AC52 F825 AFEC 58DA
-----BEGIN PGP SIGNATURE-----
Version: PGP Personal Privacy 6.5.8
iQA/AwUBPGsG8KxS+CWv7FjaEQK6fgCguMKE7Gt6JSSnKV99a5S1xcbhwFcAnRVq
FDjjm0cGY+8UryMgHDi4BALk
=ZdlA
-----END PGP SIGNATURE-----
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list