[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: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 18 Nov 2003 17:08:19 GMT
matthew chaput
 ent-Length: 1089

   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>


Well the tags aren't spilt (just duplicated) the element is split.
Especially when using xslt, it's good to preserve the distinction
between tags and elements (there's roughly twice as many tags, but xslt
has no access to them at all)

   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?

You can do one of at least three methods:

1) use a separate stylesheet producing a normalised doc used as input to
   your main stylesheet
2) use the same templates as above but do it into a variable then use
   your processors node-set() extension function to apply your main
   templates to this normalised data, so you do it in one stylesheet but as
   two passes.
3) merge the merging process in with your transform, modifying teh
   templates for all affected elements to pull in siblings.


The templates for the merge in plan 1 or 2 would look something like (untested)

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="node()"/>
<xsl:call-template name="merge"/>
</xsl:copy>
</xsl:template>

<xsl:template name="merge"/>
 <xsl:param name="start" select="."/>
 <xsl:variable name="next" select="following-sibling::node()[1]"/>
 <xsl:if test="name($next)=name($start)">
 <xsl:for-each select="$next">
   <xsl:copy-of select="node()"/>
   <xsl:call-template name="merge"/>
 </xsl:for-each>
</xsl:template>

<xsl:template match="*[name()=name(preceding-sibling::node())"/>


Plan 3 would be similar but instead of doing this on * you'd do it in
each template and you'd replace the copy-of with applying
templates of some kind to do your main transformation.

David

-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 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.