Subject: RE: [xsl] Adding Missing Element From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 24 Jan 2008 00:45:26 -0000 |
When a literal result element (<B> in this case) is copied to the result document then it is copied with all its in-scope namespaces (xmlns:c="http://bar.com/ns" in this case). You can prevent this (probably) using exclude-result-prefixes="c". I say "probably" because the rules, especially in 1.0, aren't completely prescriptive for this case where you have two prefixes bound to the same namespace uri. Michael Kay http://www.saxonica.com/ > -----Original Message----- > From: Plana, Richard [mailto:Richard.Plana@xxxxxxxxxxxxxxxx] > Sent: 24 January 2008 00:32 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] 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: [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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Adding Missing Element, Plana, Richard | Thread | Re: [xsl] Adding Missing Element, David Carlisle |
RE: [xsl] Adding Missing Element, Plana, Richard | Date | [xsl] combining multiple documents, Steven Ericsson-Zeni |
Month |