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

RE: creating container elements

Subject: RE: creating container elements
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Tue, 6 Apr 2004 13:44:30 +0100
container elements
If you input is as follows:

<foo>
  <bar id="bar-1">
    <barfoo id="barfoo-1"/>
  </bar>
  <bar id="bar-2">
    <barfoo id="barfoo-2"/>
  </bar>
  <bar id="bar-3">
    <barfoo id="barfoo-3"/>
  </bar>
</foo>

And all you want to do is wrap all the <bar> elements in a single
<container> elements, you can use:

  <xsl:template match="foo">
    <foo>
      <container>
        <xsl:copy-of select="bar"/>
      </container>
    </foo>
  </xsl:template>

Note, you can create 'literal result elements' such as <container> by
writing them directly without using <xsl:element name="container">.

If your input is a little more complated, for example:

<foo>
  <apple/>
  <orange/>
  <apple/>
  <pear/>
  <apple/>
<foo>

An you would like to wrap all <apple>'s in a <container>, then process
any other elements you can use:

<xsl:template match="foo">
  <foo>
    <container>
      <xsl:copy-of select="apple"/>
    </container>
    <xsl:apply-templates select="*[not(self::apple)]"/>
  </foo>
</xsl:template>

You won't need to use modes here,

cheers
andrew

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.