-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk]
Sent: Wednesday, January 23, 2008 4:45 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] 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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--