[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Adding Missing Element

Subject: RE: Adding Missing Element
From: "Plana, Richard" <Richard.Plana@xxxxxxxxxxxxxxxx>
Date: Wed, 23 Jan 2008 19:32:25 -0500
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.