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

RE: Joining sibling tags

Subject: RE: Joining sibling tags
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 18 Nov 2003 17:34:43 -0000
children of siblings
> 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

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.