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 April 13th, 2010, 04:44 PM
Registered User
 
Join Date: Apr 2010
Posts: 8
Thanks: 4
Thanked 0 Times in 0 Posts
Default Simplifying XML parents [XSLT]

I have an XML file that looks like this:
Code:
<A>
   <B.../>
   <C.../>
   <C.../>
   <C.../>
   <D.../>
   <D.../>
</A>
I am trying to come up with a way to format it like this using XSLT:
Code:
<A>
   <B.../>
   <C.../>
   <D.../>
</A>
I have tried a number of things like using for-each loops that compare the current name to the following-sibling and proceeding with that, however i run into problems when there are multiple, multiple instances. Ex. It works fine if there are multiple instances of ONLY C, but if there are multiples of C AND D, then my code will print out something like this:
Code:
<A>
   <B.../>
   <C...><D...></C></D>
</A>
This is because of the for-each loop going through ALL the elements even after its done what I want.

IMPORTANT:
For this I CANNOT specify C or D specifically. The paths have to be relative axes and generic enough to use for any multiples because these documents have as many as 30-50 multiples and uniquely specifying each one is not what I want.

If anyone can offer up ideas to help me with this it would be much appreciated.

Thanks.
 
Old April 13th, 2010, 05:58 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you're using XSLT 2.0 then it's just

<xsl:for-each-group select="*" group-adjacent="node-name()">
...
</xsl:for-each-group>

If you're stuck with XSLT 1.0, then use sibling recursion (google it)
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
FrozenGrapes (April 13th, 2010)
 
Old April 13th, 2010, 06:02 PM
Registered User
 
Join Date: Apr 2010
Posts: 8
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Yeah, I am stick with 1.0. but, Ill give this a shot, looks promising. Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simplifying VBA code by using Queries deweysanchez Access VBA 1 August 31st, 2009 06:27 PM
Regarding xml-html transformation of an xml string using xslt and javascript suprakash444 XSLT 1 January 12th, 2009 01:23 AM
having issue printing child values by comparing parents value eruditionist XSLT 4 January 7th, 2009 02:34 AM
simplifying an expression Tomi XSLT 1 March 7th, 2007 06:46 AM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM





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