Re: [xsl] copy-of question

Subject: Re: [xsl] copy-of question
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Apr 2001 08:28:25 +0100
Hi Franz,

> Yes. The default rules gives the unmatched elements back as
> unformattet text I guess. Coult You give me an example to extract
> only an element out of a huge xml?

Well, you can either approach it from a pull direction or a push

If you want to pull, then you should find an XPath that identifies the
single node that you want to copy from the root node of the tree,
perhaps through id() or by stepping down to it. I don't know what your
XML looks like, unfortunately, so I can only say that:


will work to point at the TABLE element in your XML.  There may be a
much better path - this one is far from optimal because it uses the
descendant-or-self:: axis, which is very inefficient.

Then you should have a single template that operates very near the top
of the tree (often the root node), and that copies only this one node:

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

The push method would involve changing the default templates.  To get
no output by default, you only need to change the template that
matches text() nodes, making it do nothing rather than giving the
value of the text.  So just add the template:

<xsl:template match="text()" />

to your current stylesheet.

Which one is most efficient depends on the structure of your XML, the
processor you're using and whether you can come up with a better XPath
to access the node you're interested in.  Generally I'd go for pull in
this situation.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread