This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: collapsing consecutive elements
- From: "G. Ken Holman" <gkholman at CraneSoftwrights dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Sun, 20 Jan 2002 14:47:55 -0500
- Subject: Re: [xsl] collapsing consecutive elements
- References: <200201181839.SAA20344@penguin.nag.co.uk>
- Reply-to: xsl-list at lists dot mulberrytech dot com
At 2002-01-20 14:25 -0500, Saverio Perugini wrote:
>How would you reverse this process?
I'm assuming the whitespace between elements is not significant, but if it
is then I'll leave it to you to add to my suggestion below. Same goes for
attributes and other content, but I thought you would only be focused on
the element explosion.
Note how the <xsl:param> ignores the default value if it is supplied a value.
This solution relies on a template being both matchable and callable, so as
to not have to duplicate functionality.
I hope this helps.
................... Ken
t:\ftemp>type saverio.xml
<?xml version="1.0" encoding="utf-8"?>
<db>
<a_b_c>
<d/>
<e/>
</a_b_c>
<f_g_h>
<i/>
<j/>
</f_g_h>
</db>
t:\ftemp>type saverio.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="*" name="continue">
<xsl:param name="name" select="name(.)"/>
<xsl:choose>
<xsl:when test="contains($name,'_')">
<xsl:element name="{substring-before($name,'_')}">
<xsl:call-template name="continue">
<xsl:with-param name="name"
select="substring-after($name,'_')"/>
</xsl:call-template>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="{$name}">
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
t:\ftemp>xt saverio.xml saverio.xsl
<?xml version="1.0" encoding="utf-8"?>
<db>
<a><b><c>
<d/>
<e/>
</c></b></a>
<f><g><h>
<i/>
<j/>
</h></g></f>
</db>
t:\ftemp>rem Done!
--
Upcoming: 3-days XSLT/XPath and/or 2-days XSLFO - Feb 18-22, 2002
G. Ken Holman mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6 Definitive XSLT & XPath
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1 Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed),
articles, training(instructor-live,Internet-live,web/CD,licensed)
Next public training: 02-02-11,12,14,15,18,21,03-04,05,06,08,11,
- 04-08,09,10,12,05-14,15,06-04,07
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list