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

Re: Join elements by name, with spaces in between

Subject: Re: Join elements by name, with spaces in between
From: Yves Forkl <Y.Forkl@xxxxxx>
Date: Mon, 12 Feb 2007 16:54:50 +0100
Re:  Join elements by name
Michael Kay schrieb:
Try group-adjacent using a grouping key of

group-adjacent="if (. instance of element()) then name(.) else
name(following-sibling::*[1])"

This groups text nodes with the following element, which may not be what you
want. If you only want to retain text nodes if they fall between to element
nodes that are in the same group, you could try to expand the conditional
above.

Thank you very much for this expression that would have taken me weeks to come up with...


You are right that I want to include spaces in an element only if the space was formerly between instances of the same element, so I have expanded the conditional expression as follows (sorry for the mangled indentation):

<xsl:template match="e">
<xsl:copy>
<xsl:for-each-group select="node()"
group-adjacent="if (. instance of element()) then name(.) else
(if (name(preceding-sibling::*[1]) eq name(following-sibling::*[1]))
then name(preceding-sibling::*[1]) else 'space_outside')">
<xsl:element name="name(current-group()[1])">
<xsl:apply-templates select="current-group()/text()"/>
</xsl:element>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>


So far I haven't been able to test if it works because I don't know how to dynamically set the "new" element's name in xsl:element from the element which is the "leader" of the current group. Am I going the wrong way about joining instances of the same element type?

To recall, I want to transform this

<e><x>x</x> <a>a1</a> <a>a2</a> <b>b</b> <c>c1</c> <c>c2</c> <a>a3</a></e>

into this:

<e><x>x</x> <a>a1 a2</a> <b>b</b> <c>c1 c2</c> <a>a3</a></e>

Yves

Current Thread

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.