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

Removing Namespace declaration from root element [xsl

Subject: Removing Namespace declaration from root element [xsltproc XSLT 1.0]
From: pankaj.c@xxxxxxxxxxxxxxxxxx
Date: Fri, 17 Sep 2010 12:30:04 +0530
 Removing Namespace declaration from root element  [xsl
Hello all,

I am trying to remove namespace declaration from root element in my xml 
input. Below is what it looks like:

Root Element:
=========
<chapter xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd" 
xmlns:ce="http://www.elsevier.com/xml/common/dtd" xmlns:mml="
http://www.w3.org/1998/Math/MathML" xmlns:xlink="
http://www.w3.org/1999/xlink" xmlns:aid="
http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="
http://ns.adobe.com/AdobeInDesign/5.0/" aid:pstyle="" aid5:tablestyle="" 
version="5.2" xml:lang="en" docsubtype="chp" id="c0030">
<ce:footnote id="fn0010">
======

Desired Output
=========

<chapter version="5.2" xml:lang="en" docsubtype="chp" id="c0030">
<ce:footnote id="fn0010">

I tried several ways to get this done but everytime getting odd results.

1st Sample
=======
<xsl:template match="@*|comment()|processing-instruction()|text()">
    <xsl:copy-of select="."/>
</xsl:template>

<!-- elements: create a new element with the same name, but no namespace 
-->
<xsl:template match="chapter">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
</xsl:template>

Which gives me the output. Notice the namespace declaration added to 
ce:footnote.

<?xml version="1.0" encoding="UTF-8"?>
<chapter xmlns:xlink="http://www.w3.org/1999/xlink" version="5.2" 
xml:lang="en" docsubtype="chp" id="c0030">
<ce:footnote xmlns:ce="http://www.elsevier.com/xml/common/dtd" 
id="fn0010">

I WOULD PREFER REMOVING NAMSPACE xmlns:xlink="http://www.w3.org/1999/xlink
" FROM TOP ELEMENT THOUGH THIS IS BEING USED IN OTHER CHILD ELEMENTS LIKE  
xlink:href="www.google.com".

2nd Sample (while commenting above template)
========

<xsl:template match="*|@*|comment()"> 
 <xsl:choose>
         <xsl:when test="name()='xmlns:sb'"/>
         <xsl:when test="name()='xmlns:ce'"/>
         <xsl:when test="name()='xmlns:mml'"/>
        <xsl:otherwise>
        <xsl:copy> 
                <xsl:apply-templates select="text()|*|@*|comment()"/> 
        </xsl:copy> 
        </xsl:otherwise>
 </xsl:choose>
</xsl:template>


Output [Nothing happens]
================

<chapter xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd" 
xmlns:ce="http://www.elsevier.com/xml/common/dtd" xmlns:mml="
http://www.w3.org/1998/Math/MathML" xmlns:xlink="
http://www.w3.org/1999/xlink" xmlns:aid="
http://ns.adobe.com/AdobeInDesign/4.0/" xmlns:aid5="
http://ns.adobe.com/AdobeInDesign/5.0/" version="5.2" xml:lang="en" 
docsubtype="chp" id="c0030">
<ce:footnote id="fn0010">

I did tried:

<xsl:template match="@*|comment()|processing-instruction()|text()">
    <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="*">
    <xsl:element name="{local-name()}">
      <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
</xsl:template>


Output 
===================================

<chapter xmlns:xlink="http://www.w3.org/1999/xlink" version="5.2" 
xml:lang="en" docsubtype="chp" id="c0030">
<ce:footnote xmlns:ce="http://www.elsevier.com/xml/common/dtd" 
id="fn0010">

Notice again the unexpected namespace declaration in <ce:footnote>

I am using commands --noout --novalid in xsltproc.

Other than that I am getting MathML parser warning while transforming:

parser warning : xmlns:mml: '-//W3C//DTD MathML 2.0 Mod ES//EN' is not a 
valid URI
//www.elsevier.com/xml/common/dtd" xmlns:mml="-//W3C//DTD MathML 2.0 Mod 
ES//EN"

Is this not a valid URL? Do the prefix "mml" causing the problem for the 
valid URL or in larger picture IS THIS WARNING COULD BE REASON FOR GETTING 
ARBITRARY RESULT?

Any suggestions will be appreciated.

TIA,
Pankaj

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.