xsl-list
[Top] [All Lists]

RE: How to combine consecutive input nodes into one output node?

2004-12-06 12:55:12
The keyword for your search is "XSLT positional grouping".

XSLT 2.0 makes it very easy: there's a construct

<xsl:for-each-group select="text:p" group-adjacent="@text:style-name">

that does exactly what you need. It's much harder in 1.0, but it can be done
(anything can be done!) with recursive templates.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Gerald Wharney [mailto:geraldwharney(_at_)yahoo(_dot_)co(_dot_)uk] 
Sent: 06 December 2004 18:09
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How to combine consecutive input nodes into 
one output node?

Hi

I've only just started working with XML and XSL. What
I'm trying to do is to write a simple XSLT that will
change an Openoffice Writer document into fairly
presentable (X)HTML. I've accomplished most of what I
need to do except the following:

What I need to know is how to transform a bunch of
consecutive similar nodes into a single output node.

For example:

< ... >
<text:p text:style-name="Listing">Line 1</text:p>
<text:p text:style-name="Listing">Line 2</text:p>
<text:p text:style-name="Listing"><text:s
text:c="4"/>Line 3 (indented)</text:p>
<text:p text:style-name="Listing"><text:s
text:c="4"/>Line 4 (indented)</text:p>
<text:p text:style-name="Listing">Line 5</text:p>
< ... >

Here I need to combine all the _consecutive_ <text:p>
nodes which have the attribute "text:style-name" equal
to "Listing" so that the output looks something like:

<p class="Listing>
Line 1
Line 2
    Line 3 (indented)
    Line 4 (indented)
Line 5
</p>

Note that I need to take into account the <text:s>
nodes which provide the spacing and are interspersed
amongst the <text:p> nodes.

Any code, pointers to FAQs/manuals, or even keywords
to Google for will be much appreciated.

tia

=====
-- 
G W (no bush)


              
___________________________________________________________ 
Moving house? Beach bar in Thailand? New Wardrobe? Win £10k 
with Yahoo! Mail to make your dream a reality. 
Get Yahoo! Mail www.yahoo.co.uk/10k

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>