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

Re: XML elments order

Subject: Re: XML elments order
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Dec 2001 10:50:04 +0000
elments
Hi,

> I'm trying to convert an XML document into another XML document and
> I need to keep tags in the same order has they appear in the first
> document.

Probably you are telling the processor to first process the names, and
then process the content, using:

  <xsl:for-each select="name">
    ...
  </xsl:for-each>
  <xsl:for-each select="content">
    ...
  </xsl:for-each>

If you want to process them in document order, you have to tell the
processor to process them all, and then use something inside the
xsl:for-each to work out what kind of element's being processed:

  <xsl:for-each select="name | content">
    <xsl:choose>
      <xsl:when test="self::name">
        ...
      </xsl:when>
      <xsl:when test="self::content">
        ...
      </xsl:when>
    </xsl:choose>
  </xsl:for-each>

As you can see, that would get tedious if you had lots of different
kinds of elements, and difficult to manage if the elements nested
inside each other. Mostly, therefore, for this kind of processing, a
push approach is a better approach. In the push approach, you tell the
processor to apply templates to all the nodes:

  <xsl:apply-templates />

And then you have a number of templates that match the different kinds
of nodes and do something with them, so one template for names and one
template for content elements:

<xsl:template match="name">
  ...
</xsl:template>

<xsl:template match="content">
  ...
</xsl:template>
  
I hope that helps,

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.