[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Matching on of many string literal values using XPath


Subject: RE: [xsl] Matching on of many string literal values using XPath
From: TSchutzerWeissmann@xxxxxxxxxxxxxxxx
Date: Fri, 13 Sep 2002 09:38:13 +0100

Hello Richard,

> I would like to select all nodes from a particular set of 
> elements that
> matches one of several values.  Is there a simpler way of 
> doing it then
> what is below?
> 
>   <xsl:template match="client/race[text()='white'] |
> 		       client/race[text()='black'] |
> 		       client/race[text()='asian'] |
> 		       client/race[text()='hispanic'] |
> 		       agencies/race_served[text=()='white'] |
> 		       agencies/race_served[text=()='black'] |
> 		       agencies/race_served[text=()='asian'] |
> 		       agencies/race_served[text=()='hispanic'] 
> ">   

> I would like to define all of the string literals (white,black,etc) in
> one place (a variable?) then just specify the paths I want to 
> match 

you could make a variable that concatenates all the different 
values you'd like to test for and use contains() to do the 
test.
ie 
	<xsl:variable name="raceList">
		<xsl:text>white|black|asian|hispanic</text>
	</xsl:variable>

	and 

	<xsl:template match="client/race[contains($raceList,.)]
		 |
 	agencies/race_served[contains($raceList,.)]">

---
Tom

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



Current Thread