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

Re: Process some elements, but not others...

Subject: Re: Process some elements, but not others...
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 13 Feb 2003 20:25:31 -0700 (MST)
element bu
Ted Stresen-Reuter wrote:
> I have an xml document whose elements contain html as in the following 
> example:
> 
> <myelement>
>      <p>This is <ref>the</ref> text node</p>
> </myelement>
> 
> What I'd like to be able to do is transform just the ref element and 
> copy all the others.

This is more or less in the XSLT 1.0 spec, under Copying.

The "identity transform" described there is a template that has a relatively
low priority and recursively copies all nodes from the source tree to the
result. If you supplement that template with another that, by virtue of 
matching with a more specific node test than the other, has a higher priority, 
then you can override the identity transform for certain elements:

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

<!-- replace a ref element with its children -->
<xsl:template match="ref">
  <xsl:apply-templates/>
</xsl:template>


Also, just FYI, your source tree has a structure like this:

root
 |
 |__element 'myelement'
      |
      |__text '\n     '
      |
      |__element 'p'
      |    |
      |    |__text 'This is '
      |    |
      |    |__element 'ref'
      |    |    |
      |    |    |__text 'the'
      |    |
      |    |__text ' text node'
      |
      |__text '\n'

...that is, "This is the text node" is not very accurate; the phrase is split
among 3 different text nodes, although if you use the templates above, you'll
end up with one :)

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

 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.