Re: [xsl] Process some elements, but not others...

Subject: Re: [xsl] Process some elements, but not others...
From: Ted Stresen-Reuter <tedmasterweb@xxxxxxx>
Date: Fri, 14 Feb 2003 10:39:36 -0600
Hi Mike,

Thanks for the reply. I'm still new at XSLT so I'm not sure I fully understand the concept presented, but I tried it, to the best of my ability, and it didn't work. I think it's time to come forth and just be honest...

I'm trying to lend a hand on the htdig project ( They have a document called defaults.xml which contains the default values for the configuration attributes. I've documented what I'm working on here:

I've tried a variety of variations on the procedure you suggest, but it just doesn't seem to work, so, I'm reposting the question with a little better example...

Sample XML
<attribute name="accents_db" type="string_list" programs="htdig">
<example>search_algorithm, search_results_header</example>
<p>bla bla bla bla bla bla <strong>bla bla</strong> bla bla bla <em>bla</em></p>
<p>bla bla <ref>bla</ref> bla, bla!</p>

Sample XSL
<xsl:output method="xml"
doctype-public="-//W3C/DTD XHTML 1.0 Transitional//EN" indent="yes" encoding="ISO-8859-1" />

<xsl:template match="/">
    <xsl:apply-templates />

<xsl:template match="HtdigAttributes">
    <xsl:apply-templates select="attribute" />

<xsl:template match="attribute">
<!-- we do a bunch of fun transofrmations here -->
<xsl:value-of select="@name" />
<xsl:value-of select="@type" />
<!-- would like to have the value of the description node here, but with all HTML elements left in tact and all "ref" elements transformed -->

Any suggestions on changes that would make your suggestion work in this context?

Thanks again!


On Thursday, February 13, 2003, at 09:25 PM, Mike Brown wrote:

Ted Stresen-Reuter wrote:
I have an xml document whose elements contain html as in the following

     <p>This is <ref>the</ref> text node</p>

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>

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

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

 |__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 J. Brown   |
  Denver, CO, USA |

XSL-List info and archive:

XSL-List info and archive:

Current Thread