This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to highlight arbitrary elements depending on xsl:param?
- To: xsl-list at mulberrytech dot com
- Subject: Re: How to highlight arbitrary elements depending on xsl:param?
- From: Sebastian Rahtz <sebastian dot rahtz at computing-services dot oxford dot ac dot uk>
- Date: Thu, 12 Oct 2000 09:31:18 +0100
- cc: jakob at free dot fr
- References: <971306688.39e4f6c0c6589@imp.free.fr>
- Reply-To: xsl-list at mulberrytech dot com
Jakob writes:
> I have an xsl stylesheet which I'd like to use for plain display of
> documents as well as for display of documents containing search
> hits. In the latter case I'd like to highlight elements containing
> a hit, by outputting some basic html of the kind <b
> style='background-color: gold'> and </b> immediately inside the
> element.
no doubt you meant to type <span class="highlight"> here :-}
> I know about the GI of the hit element through the value of an <xsl:param
> name='matchElement'/>.
>
> What I can't figure out is how to avoid writing <xsl:if> clauses
> for all the many dozens of elements of the DTD. Surely, there must
> be a way to just write on template that fits all?! [Maybe it's just
> too late.]
Would some mode work do the job?
<xsl:template match="*" mode="highlight">
<xsl:param name="elemName"/>
<xsl:choose>
<xsl:when test="name(.) = $elemName">
<b><xsl:apply-templates select="."/></b>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
but I am not sure I have guessed enough about the structure of your
stylesheet to see how this can fit in? perhaos if you posted a
skeleton of your existing code it would be clearer.
Sebastian
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list