Re: [xsl] Finding a specific element and outputting another related elements value

Subject: Re: [xsl] Finding a specific element and outputting another related elements value
From: Adam Turoff <ziggy@xxxxxxxxx>
Date: Tue, 10 Jul 2001 15:54:02 -0400
On Tue, Jul 10, 2001 at 03:00:16PM -0400, Linda Zammit wrote:
> Hello all,
> I don't know if this is possible:
> 
> I need to output the contents of one element dependant on the previous
> elements content (i.e. if RemarkQualifier=DIMENSIONS then output '24 @
> 48"X48"X48"'.
> 
> XML:
> <Release>
> 	<OrderRemark>
> 		<RemarkQualifier>DIMENSIONS</RemarkQualifier>
> 		<RemarkText>24 @ 48"X48"X48"</RemarkText>
> 	</OrderRemark>
> </Release>
> <Release>
> 	<OrderRemark>
> 		<RemarkQualifier>PIECES</RemarkQualifier>
> 		<RemarkText>24</RemarkText>
> 	</OrderRemark>
> </Release>

First, list the processing expectations in detail:

	1) From <RemarkText>, 
	2) examine the previous element's content, 
	3) when that element is a RemarkQualifer,
	4) and when that element's content is 'DIMENSIONS'
	5) display the contents of this element.

Here's a solution:

<xsl:template match="RemarkText">  
 <xsl:if test="preceding-sibling::RemarkQualifier[1][text()='DIMENSIONS']">
  <xsl:value-of select="text()"/>
 </xsl:if>
</xsl:template>

That should do it.

Z.


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


Current Thread