[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Adding Missing Element
-----Original Message----- From: David Carlisle [mailto:davidc@xxxxxxxxx] Sent: Wednesday, January 23, 2008 4:45 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: Adding Missing Element > One question, though: currently, all added nodes from the template seem > to have an xmlns:n attribute added to the element. Where can I switch > off the functionality that does this? (and yes, <A> belongs to the > namespace n). XSLT will not add namespace declarations to the output if that namespace binding is already in scope from an ancestor element. So barring a bug in your system, the output is probably not quite as this description would indicate, can you post a small example. Input file: <?xml version="1.0"?> <foo xmlns="http://bar.com/ns"> <A/> <A><B/></A> <A/> <A><B><C/></B></A> </foo> Transform: <?xml version="1.0" encoding="UTF-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:c="http://bar.com/ns" > <!-- The identity transform --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="c:A"> <xsl:variable name="count" select="count(descendant-or-self::c:B)"/> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> <xsl:if test="$count = 0"> <B> ZZZZZZZ </B> </xsl:if> </xsl:copy> </xsl:template> </xsl:transform> Output: <?xml version="1.0" encoding="UTF-8"?><foo xmlns="http://bar.com/ns"> <A><B xmlns:c="http://bar.com/ns"> ZZZZZZZ </B></A> <A><B/></A> <A><B xmlns:c="http://bar.com/ns"> ZZZZZZZ </B></A> <A><B><C/></B></A> </foo> Bug in my XSLT engine? -- Richard Plana
|
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
|