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 July 15th, 2013, 02:16 AM
Registered User
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Merging 2 consecutive List items in XSLT

Hi all,

I have a XML which has list items like

<list type="expl" margin="0">
<li label="(1)">
<p num="n">
<text>
(1) A person
is guilty of an offence if:
</text>
</p>
</li>
</list>
<list type="expl" margin="0">
<li label="(a)">
<p num="n">
<text>
(a) the
person deals with money or other property; and
</text>
</p>
</li>
</list>


The output i need is like

<list type="expl">
<li label="(1)">
<p num="n">
<text>A person is guilty of an offence if:</text>
</p>
<list type="expl">
<li label="(a)">
<p num="n">
<text>the person deals with money or other property; and</text>
</p>
</li>
</list>
</list>

Effectively if List appears as consecutive siblings, and they are of different types (eg, (1)/(a)/(i)) they must be nested inside the previous list item.

Thanks
Srini
 
Old July 15th, 2013, 03:09 AM
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, take a look at

Code:
<xsl:for-each-group group-adjacent="..."/>
If you're not using XSLT 2.0, perhaps it's time to upgrade?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old July 15th, 2013, 07:13 AM
Registered User
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael for your reply.

Any idea how we could do it with the patterns that I have specified (1)/(a)/(i) etc, group-adjacent wud group with a common attribute value.

If you could elaborate on the code it will be really great as I have not come across such a thing before

Thanks in advance

Srini
 
Old July 15th, 2013, 08:56 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The requirement to group adjacent items that are different, and not group those that are the same, is rather unusual, but you could do it using

Code:
group-ending-with="@label[not(. = following-sibling::*/@label)]"
__________________
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
Merging XML Files Using XSLT darkknight XSLT 1 October 9th, 2012 05:36 AM
merging 2 xml with xslt gbordel XSLT 7 April 24th, 2008 05:27 AM
merging xml using xslt sormel XSLT 1 July 9th, 2007 06:07 PM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
Consecutive Grouping kilika SQL Server 2000 2 July 8th, 2003 07:02 PM





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