[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Matching a first instance.

Subject: Matching a first instance.
From: Ben Trafford <ben@xxxxxxxxxxx>
Date: Fri, 28 Nov 2003 21:26:28 -0500
first instance

Hi!

I have a somewhat unusual problem. I want to match an xsl:if test to the first occurrence of an element with an attribute of a particular value. An example snippet of XML to be transformed:


<TestElement xmlid="testID">
<adder xmlid="personal" cost="2" alias="personal computers" />
<adder xmlid="handheld" cost="2" alias="handheld computers" />
<adder xmlid="network" cost="2" alias="networked computers" />
<adder xmlid="mainframe" cost="2" alias="mainframe" />
</TestElement>

The test needs to find all the TestElements whose xmlid is 'testID''. Then find the first child element whose xmlid matches any of those listed. Then change that child element's "cost" attribute to "0". Leave the other "cost" attributes alone.


So, the above snippet would be changed to:

<TestElement xmlid="testID">
	<adder xmlid="personal" cost="0" alias="personal computers" />
	<adder xmlid="handheld" cost="2" alias="handheld computers" />	
	<adder xmlid="network" cost="2" alias="networked computers" />
	<adder xmlid="mainframe" cost="2" alias="mainframe" />
</TestElement>

The following snippet:

<TestElement xmlid="testID">
	<adder xmlid="Not_In_The_Set_To_Be_Recognized"
	<adder xmlid="handheld" cost="2" alias="handheld computers" />	
</TestElement>

would be changed to:

<TestElement xmlid="testID">
<adder xmlid="Not_In_The_Set_To_Be_Recognized" cost="1" alias="Not In The Set We Care About" />
<adder xmlid="handheld" cost="0" alias="handheld computers" />
</TestElement>


And the following:

<TestElement xmlid="testID">
<adder xmlid="Not_In_The_Set_To_Be_Recognized" cost="1" alias="Not In The Set We Care About" />
<adder xmlid="handheld" cost="2" alias="handheld computers" />
<adder xmlid="Not_In_The_Set_To_Be_Recognized" cost="1" alias="Not In The Set We Care About" />
<adder xmlid="personal" cost="2" alias="personal computers" />
</TestElement>
<TestElement xmlid="testID">
<adder xmlid="personal" cost="2" alias="personal computers" />
<adder xmlid="handheld" cost="2" alias="handheld computers" />
<adder xmlid="Not_In_The_Set_To_Be_Recognized" cost="1" alias="Not In The Set We Care About" />
</TestElement>


would become:

<TestElement xmlid="testID">
<adder xmlid="Not_In_The_Set_To_Be_Recognized" cost="1" alias="Not In The Set We Care About" />
<adder xmlid="handheld" cost="0" alias="handheld computers" />
<adder xmlid="Not_In_The_Set_To_Be_Recognized" cost="1" alias="Not In The Set We Care About" />
<adder xmlid="personal" cost="2" alias="personal computers" />
</TestElement>
<TestElement xmlid="testID">
<adder xmlid="personal" cost="0" alias="personal computers" />
<adder xmlid="handheld" cost="2" alias="handheld computers" />
<adder xmlid="Not_In_The_Set_To_Be_Recognized" cost="1" alias="Not In The Set We Care About" />
</TestElement>


Any help would be much appreciated. Note that the "xmlid" attributes being used are -not- unique. They will re-occur.

--->Ben


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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.