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

AW: [xsl] XSLT Question


Subject: AW: [xsl] XSLT Question
From: Markus Abt <abt@xxxxxxxx>
Date: Wed, 20 Aug 2003 22:04:18 +0200

Hi Alden,

for a first solution, you could try replacing the outer loop:
<xsl:for-each select="//Fruit">
by:
<xsl:for-each select="//Fruit[not(@ID = preceding-sibling::Fruit/@ID)]">
to process only the first occurrence of a Fruit's ID.

A far better solution would be to use "Muenchian Grouping". Search:
http://www.google.com/search?q=muenchian+grouping

Regards,
Markus
__________________________
Markus Abt
Comet Computer GmbH
http://www.comet.de


----------
Von: 	Lee, Insoo
Gesendet: 	Mittwoch, 20. August 2003 17:44
An: 	'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Cc: 	Penn, Alden
Betreff: 	[xsl] XSLT Question



I am currently using an XSLT stylesheet to transform one type of XML into
another.  The first type looks like this:

<FruitList>
	<Fruit ID="5" KEY="apple" VALUE="true">
	<Fruit ID="5" KEY="orange" VALUE="false">
	<Fruit ID="4" KEY="orange" VALUE="false">
	<Fruit ID="5" KEY="banana" VALUE="false">
	<Fruit ID="4" KEY="pineapple" VALUE="false">
	<Fruit ID="13" KEY="orange" VALUE="false">
	<Fruit ID="13" KEY="watermelon" VALUE="true">
	<Fruit ID="4" KEY="kiwi" VALUE="false">
	<Fruit ID="4" KEY="grapefruit" VALUE="true">
	<Fruit ID="13" KEY="papaya" VALUE="false">
	<Fruit ID="13" KEY="honeydew" VALUE="true">
</FruitList>

I'd like to write a stylesheet to transform it as follows:

<FruitList>
	<Fruit ID="5">
		<Property KEY="apple" VALUE="true">
		<Property KEY="orange" VALUE="false">
		<Property KEY="banana" VALUE="false">
	</Fruit>
	<Fruit ID="4">
		<Property KEY="orange" VALUE="false">
		<Property KEY="pineapple" VALUE="false">
		<Property KEY="kiwi" VALUE="false">
		<Property KEY="grapefruit" VALUE="true">
	</Fruit>
	<Fruit ID="13">
		<Property KEY="orange" VALUE="false">
		<Property KEY="watermelon" VALUE="true">
		<Property KEY="papaya" VALUE="false">
		<Property KEY="honeydew" VALUE="true">
	</Fruit>
</FruitList>


So far, using a <xsl:for-each select="//Fruit">  with a nested <xsl:for-each
select="//Fruit[@ID=$a]"> where $a = the current ID, I've been able to get
the XML to look like the following:

<FruitList>
	<Fruit ID="5">
		<Property KEY="apple" VALUE="true">
		<Property KEY="orange" VALUE="false">
		<Property KEY="banana" VALUE="false">
	</Fruit>
	<Fruit ID="5">
		<Property KEY="apple" VALUE="true">
		<Property KEY="orange" VALUE="false">
		<Property KEY="banana" VALUE="false">
	</Fruit>
	<Fruit ID="5">
		<Property KEY="apple" VALUE="true">
		<Property KEY="orange" VALUE="false">
		<Property KEY="banana" VALUE="false">
	</Fruit>
	<Fruit ID="4">
		<Property KEY="orange" VALUE="false">
		<Property KEY="pineapple" VALUE="false">
		<Property KEY="kiwi" VALUE="false">
		<Property KEY="grapefruit" VALUE="true">
	</Fruit>
	<Fruit ID="4">
		<Property KEY="orange" VALUE="false">
		<Property KEY="pineapple" VALUE="false">
		<Property KEY="kiwi" VALUE="false">
		<Property KEY="grapefruit" VALUE="true">
	</Fruit>
	<Fruit ID="4">
		<Property KEY="orange" VALUE="false">
		<Property KEY="pineapple" VALUE="false">
		<Property KEY="kiwi" VALUE="false">
		<Property KEY="grapefruit" VALUE="true">
	</Fruit>
	<Fruit ID="4">
		<Property KEY="orange" VALUE="false">
		<Property KEY="pineapple" VALUE="false">
		<Property KEY="kiwi" VALUE="false">
		<Property KEY="grapefruit" VALUE="true">
	</Fruit>

..

</FruitList>

In other words, it prints out a seperate Fruit tag in the transformed XML
for each of the Fruit tags in the original when I want it to only print out
one fruit tag for each ID.  How do I get the XSLT to "skip" rows I've
already processed?  I tried saving the processed ID in a variable and
testing to see if the new ID is equal to the old ID, but because of scoping
issues it won't work.  Any ideas?


Thanks,

Alden


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



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



Current Thread
Keywords