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

Re: Antw: Re: flatten a hierachy and change positions

Subject: Re: Antw: Re: flatten a hierachy and change positions
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 25 Sep 2003 12:43:53 +0100
keep the hierachy
Hi Elke,

> thanks, I tried your examples. Just one probably very simple
> question is left. What do I have to change to keep my content, not
> just the elements. I assume with this additional part I would get
> both, opening and closing tags wouldn't I?

I assume that the XML that you're using is data-oriented: that every
element either contains other elements or contains some text that you
want to keep.

In that case, you could use something like:

<xsl:template match="*">
  <xsl:apply-templates select="*" />
  <xsl:copy>
    <xsl:apply-templates select="text()" />
  </xsl:copy>
</xsl:template>

With this template, if an element just contains other elements then
those elements will be processed first, and then there will be an
empty copy of the element itself. If an element contains text, then
you will get a copy of the element with the text that it contains
within the copy.

Alternatively, you could have different templates for the elements
that you want to be treated differently. If you want an element to be
copied with all its content, then use something like:

<xsl:template match="u1">
  <xsl:copy-of select="." />
</xsl:template>

If you want an empty copy of the element to appear before its content,
then use:

<xsl:template match="g1">
  <xsl:copy />
  <xsl:apply-templates select="*" />
</xsl:template>

and so on.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.