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

Re: XSLT Question

Subject: Re: XSLT Question
From: Mukul Gandhi <mukulw3@xxxxxxxxx>
Date: Wed, 20 Aug 2003 21:00:57 -0700 (PDT)
properties xslt tag
Please use Muenchian method for grouping. Below is the
complete XSL --

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
   <xsl:key name="x" match="Fruit" use="@ID"/>
   
   <xsl:template match="/FruitList">
     <Fruitlist>
       <xsl:for-each select="Fruit">
	 <xsl:if test="generate-id(.) = generate-id(key('x',
@ID)[1])">
	 <Fruit ID="{@ID}">
	   <xsl:for-each select="key('x', @ID)">
              <Property KEY="{@KEY}" VALUE="{@VALUE}">
                                   
              </Property>
           </xsl:for-each>
         </Fruit>    
	</xsl:if>
      </xsl:for-each>
   </Fruitlist>
</xsl:template>
</xsl:stylesheet>

Regards,
Mukul

--- "Lee, Insoo" <Insoo.Lee@xxxxxx> wrote:
> 
> 
> 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
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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


Current Thread
  • XSLT Question
    • Lee, Insoo - Wed, 20 Aug 2003 11:46:13 -0400 (EDT)
      • Michael Kay - Wed, 20 Aug 2003 17:28:57 -0400 (EDT)
      • Mukul Gandhi - Thu, 21 Aug 2003 00:01:36 -0400 (EDT) <=

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.