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

Re: move tag up to level

Subject: Re: move tag up to level
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 29 Sep 2006 12:28:40 +0100
moving tags xsl
Don't think in terms of "closing tags" or "moving tags" anywhere.
XSLT does not work with tags, and thinking in those terms just makes it
harder to use XSLT.

What you want to do is take the children of a and group them into groups
of adjacent nodes that are either b elements or not b elements.
b elements you just want to copy, and each group of not-b elements you
want to place as a child of an a element. 

So you use for-each-group gruping on a boolean test for a node being a b
element, like so:



<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:template match="*">
    <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

 <xsl:template match="a">
   <xsl:for-each-group select="node()" group-adjacent="exists(self::b)">
     <xsl:choose>
       <xsl:when test="self::b">
	 <xsl:apply-templates select="current-group()"/>
       </xsl:when>
       <xsl:otherwise>
	 <a>   
	   <xsl:copy-of select="../@*"/>
	   <xsl:apply-templates select="current-group()"/>
	 </a>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:for-each-group>
</xsl:template>


</xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.