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

Re: putting all the elements with a given name one lev

Subject: Re: putting all the elements with a given name one level up
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 28 Jun 2004 19:54:22 -0400
how elements given name
At 2004-06-29 00:07 +0100, Pedro Castro wrote:
I have this xml:
...
And I want to transform it to this one:
(The difference is that all the ccc elements, and it's children are removed
from the location where they are and putted below the root element)

This can be done in a straightforward fashion by modifying the identity transformation.


I hope the example below helps. I've turned on indentation for illustration that may not apply in your case ... remember to remove the template at the end of the example that eats white-space-only text nodes.

.............. Ken

T:\ftemp>type pedro.xml
<root>
            <aaa>
                        <bbb/>
                        <ccc/>
                        <bbb/>
            </aaa>
            <aaa>
                        <ccc>
                                   <abc>test</abc>
                        </ccc>
                        <bbb/>
                        <bbb/>
            </aaa>
</root>

T:\ftemp>type pedro.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output indent="yes"/>

<xsl:template match="root">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    <xsl:copy-of select="//ccc"/><!--collect all ccc elements-->
  </xsl:copy>
</xsl:template>

<xsl:template match="ccc"/><!--ignore ccc elements when found-->

<xsl:template match="@*|node()"><!--identity for all other nodes-->
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<!--this cleans up the output when using indent="yes"-->
<xsl:template match="text()[not(normalize-space())]"/>

</xsl:stylesheet>
T:\ftemp>saxon pedro.xml pedro.xsl
<?xml version="1.0" encoding="utf-8"?>
<root>
   <aaa>
      <bbb/>
      <bbb/>
   </aaa>
   <aaa>
      <bbb/>
      <bbb/>
   </aaa>
   <ccc/>
   <ccc>

<abc>test</abc>

   </ccc>
</root>
T:\ftemp>


-- Public training 3 days XSLT & 2 days XSL-FO: Phoenix,AZ 2004-08-23 World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal


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.