Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 13th, 2014, 05:53 AM
Registered User
 
Join Date: Aug 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need XSL for below requirement

Hi All,

I need XSL to translate below input xml into expected output xml.

Req. in brief
I have xml which has item element with attributes itemid and type, i need to segregate those item elements based on its type. Sample input and output is as below.

input
Code:
<cat>
	<catItem item="1" type="A" />
	<catItem item="2" type="A" />
	<catItem item="3" type="B" />
	<catItem item="4" type="B" />
</cat>
---------------------------------
expected output
Code:
<cat>
	<Category type="A">
		<Item id="1" />
		<Item id="2" />		
	</Category>
	<Category type="B">
		<Item id="3" />
		<Item id="4" />		
	</Category>
</cat>
Can any one help me to develop XSL for above requirement.

Thanks,
Sandeep
 
Old August 13th, 2014, 07:02 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Is the possible set of values for "type" known in advance, or does it depend on what you find in the data?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 13th, 2014, 10:39 AM
Registered User
 
Join Date: Aug 2014
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Firstly i would like to say thank you for the response.

"type" will not be available in advance, that could be possibly 1000's occurrences.

Thanks,
Sandeep B
 
Old August 13th, 2014, 11:02 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In that case this is a standard grouping query. If you are using XSLT 2.0 look at the xsl:for-each-group instruction; with XSLT 1.0 look up "Muenchian grouping" which you will probably find in the index of your favourite Wrox XSLT textbook. The 1.0 solution appears complex but it's not difficult when you get the hang of it; it's much more straightforward in XSLT 2.0.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
SharePoint Requirement to do examples jubo6000 BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 1 January 12th, 2011 06:11 PM
convert decimal value as per requirement thava Beginning PHP 3 April 6th, 2009 04:29 AM
general question of how to implement a requirement gkelley Javascript How-To 0 July 27th, 2007 11:48 AM
urgent requirement geetha Visual Basic 2005 Basics 0 March 22nd, 2006 02:15 AM
Requirement for ASP .NET 2.0 rupen ASP.NET 2.0 Basics 7 October 21st, 2005 05:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.