Altova Mailing List Archives

RE: [xsl] How to filter nodes on attribute values

From: "XSLList" <xsllist@------------->
Date: 3/10/2003 5:43:00 PM
If you don't like my solution create separate templates for each type you
want of the form:

<xsl:template match="Annotation[@type='boring']">

which will give you more granular control over formatting.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl='' >
<xsl:output method="html"/>

<xsl:template match="/">
			.interesting {color: red;}
			.boring {color: green;}

<xsl:template match="Annotation">
	<p class="{@type}">
		Author = <xsl:value-of select="book/author"/><br/>
		Title = <xsl:value-of select="book/title"/><br/>


<?xml version="1.0"?>
	 <Annotation type="interesting">
	    <book id="bk106">
	      <author>Randall, Cynthia</author>
	      <title>Lover Birds</title>
	<Annotation type="boring">
	   <book id="bk102">
	      <author>Ralls, Kim</author>
	      <title>Midnight Rain</title>
	<Annotation type="indifferent">
	   <book id="bk102">
	      <author>Ledbetter, James</author>
			<title>Starving to Death on $200 Million</title>

>I have another problem.
>I wish to apply formatting on a set of nodes which have a certain value
>in the attribute.
>I mean -
> <Annotation type="interesting">
>    <book id="bk106">
>      <author>Randall, Cynthia</author>
>      <title>Lover Birds</title>
>    </book>
><Annotation type="boring">
>   <book id="bk102">
>      <author>Ralls, Kim</author>
>      <title>Midnight Rain</title>
>    </book>
>So that I can show all nodes ANNOTATION with
>type="interesting" with RED
>colored font and
>all nodes ANNOTAITON with type="boring" with GREEN colored font.
>Could somebody please guide me how to do this.
>I donot wish to use When or If because I have to use
>apply-imports which
>doesnot work with When and If.
>Thanks in advance

 XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.