RE: Delete XML Node
I've been somewhat reluctant to respond to your post, though it's easy enough, since it's actually hard to determine what the best answer is.
The simple answer is "wrap the output for your <Y> in a simple xsl:if to test whether your condition for outputting it is met". So your code might be:
... <xsl:for-each select="Y"> <xsl:if test="*"><!-- tests whether any element children of a Y exist --> <Y>...</Y> </xsl:if> </xsl:for-each>
But I rather think, looking at your input and desired output, that there are better solutions. Whether they are actually better depend on the exact purposes of your transform, as well as what range of inputs it has to handle, etc. So, for example, if your input is
<X> <A>A</A> <Y></Y> </X>
and your stylesheet is tasked with the job of *copying the input except Y elements that have no children*, this can easily be accomplished with a modified "identity stylesheet" (a stylesheet that copies the source tree to the result), like so:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*"> <!-- the default template for an element simply copies that element --> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template>
<xsl:template match="Y[not(*)]"/> <!-- except Y elements with no element children are removed -->
This will be both more robust, and easier to maintain and extend, than the "pull" approach you are taking using the for-each instructions.
If you don't understand how this is working, you want to do a bit of research on templates, apply-templates and the XSLT processing model, including the effect of the built-in templates.
Good luck, Wendell
At 04:03 PM 10/31/2002, you wrote:
Whoops, I shot myself in the foot here....
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
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