|
Subject: RE: [xsl] Joining sibling tags From: "Michael Kay" <mhk@xxxxxxxxx> Date: Tue, 18 Nov 2003 17:34:43 -0000 |
> I'm using a very bad XML producer (*cough*Frame*cough*) that
> splits tags
> when it finds one of its internal markers, resuling in stuff
> like this:
>
> <note>No</note><note>te:</note>
>
> How do I fix this globally for all tags in XSLT (ie combine
> contents of
> neighbor tags that have the same name() )?. Can I do it as a
> first step
> in a larger stylesheet or do I need to do it as a separate
> transformation?
>
It's nearly always better to do one job in one stylesheet.
I suspect doing this globally will actually give you problems, but you
can try it if you want. It's a positional grouping problem, easily
solved in XSLT 2.0 with
<xsl:template match="*">
<xsl:for-each-group select="child::node()" group-adjacent="name()">
<xsl:copy>
<xsl:apply-templates select="current-group()/child::node()"/>
</xsl:copy>
</xsl:for-each-group>
</xsl:template>
You haven't said what you want done with attributes, this solution drops
them.
Positional grouping in XSLT 1.0 is harder, the best approach here is
probably a recursive xsl:apply-templates along the sibling axis.
Michael Kay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Finding total hours betwe, G. Ken Holman | Thread | [xsl] Re: XSL in HTML, yguaba |
| Re: [xsl] Introducing a comma., David Carlisle | Date | [xsl] Re: XPATH, Dave Cramer |
| Month |