Re: returning nodes which have a specific child
Thanks very much for that! Worked a treat.
glad to hear it helped.
I'm relatively new to xsl and to be honest a lot of it seems like a black art. Can you briefly describe what your solution does?
Sure, see comments inline.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
I have an editor macro that produces the stylesheet skeleton plus identity template, as this is almost always the right starting point for a new stylesheet.
Note that XSLT has built-in template rules that basically lose the markup and display the text only. Most of the time you'll want to supplant these by the identity template. Some people even think that the identity template should have been the built-in template rule.
Bottom line, start with the identity template.
<xsl:template match="*" priority="-0.4" ><!-- skip unwanted --> <xsl:apply-templates select="*"/> </xsl:template>
Priority is expressed as a decimal number. It is implicit from the match pattern. In the above case, the match pattern has the same priority (-0.5) as that of the identity template. So I give it an explicit priority of -0.4 so that it takes precedence over the identity template for matching nodes.
This template matches element nodes (*). So does the identity template (by virtue of node(), which is a node test), but this one takes precedence due to a higher priority.
It doesn't do much. You want to lose these nodes, but process their child elements, so you don't copy anything and <apply-templates> to the child elements, which are selected as "*". If I didn't process child elements, well, processing would stop at this point in the input tree, which is not what I want. I want processing to go all the way downtree.
<xsl:template match="*[*[@name='CONTENT']]" ><!-- keep wanted --> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
Does that make things clearer?
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