[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Thought i knew this but i guess not
Russ,
On 2/22/2011 2:19 PM, russurquhart1@xxxxxxxxxxx wrote: I am trying to extract only elements having a filter attribute value of 'filter10', 'filter1' or has no filter attributes at all. I would have thought this would do it: Naturally. Using the templates you've given, there are two things you could get in your result: If the document element (/*) has a @filter containing 'filter10' or 'filter1', or no @filter at all, you'll get the entire document. Otherwise you'll get nothing. This is because xsl:copy-of simply copies a branch of the tree to the result. Since either one or the other of your templates will match the element at the top of the document, either it will be copied with all its attributes and descendants, or it won't. From your question it appears you expect the templates to match recursively down through a full traversal of the tree. But the copy-of instruction doesn't do that. Instead, you want the identity template, which uses xsl:copy (not copy-of) and xsl:apply-templates, to effect a traversal in the normal way. So basically what you want is a copy of the identity template, plus another template that overrides it for elements matching elements you don't want to copy, which does something special for them. (But we can't write that template until you say whether the contents of these elements might still be copied, or you expect the tree simply to be truncated at those points.) If you have trouble working it out based on this hint, I'm sure another helpful list member can be more explicit. Cheers, Wendell <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="*[@filter]"> <xsl:if test="contains(@filter, 'filter10') or contains(@filter, 'filter1')">
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|