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

Removing a single namespace

Subject: Removing a single namespace
From: Lynn Murdock <lmurdock@xxxxxxxx>
Date: Sun, 11 Dec 2011 15:39:40 -0800
 Removing a single namespace

I have an XML-to-XML transform (not the same that I recently asked about) in
which I am essentially copying everything except for a few elements that need
to be modified. However, in copying, somehow an xsi: namespace is being added
to the output, which I would like to suppress, as I don't use it. I think that
the extra namespace is being added by a combination of the NLM 3.0 DTD and the
way elements are being copied, but I'm not sure. The starting document is an
NLM 3.0 XML file; the ending document is also 3.0 XML, but slightly modified.
This particular transform is only one component in a complicated set of groovy
scripts to prepare an article package for ingest into our system; however, I
think that everything mentioned below should be self-contained within the XSL
transform, and shouldn't rely on logic from elsewhere in the set of scripts.

I came across some code to suppress a single namespace, but it isn't working
well with the transform as a whole -- depending on how I modify it, either
it's retaining some attributes that i have expressly suppressed elsewhere in
the transform, or it's not copying everything through. I think the problem has
to do with how this namespace code is interacting with the copy of everything
else, but I'm not positive.

What I want to do is suppress *only* the
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" namespace attribute from
the result document. Any ideas would be much appreciated.

Here are relevant snippets from the starting and result XML documents:

<!DOCTYPE article
  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN"
<article xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xlink="http://www.w3.org/1999/xlink" article-type="discussion"
dtd-version="3.0" xml:lang="EN">

<!DOCTYPE article
  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN"
<article xmlns:mml="http://www.w3.org/1998/Math/MathML"
article-type="discussion" dtd-version="3.0" xml:lang="EN">

Here's relevant info from the stylesheet:

XSL version="2.0"
Test processor is Oxygen's built-in Saxon; production processor will be Saxon

<!DOCTYPE xsl:stylesheet [
    <!ENTITY nlmpub  "http://dtd.nlm.nih.gov/publishing/">

<xsl:output name="nlm-3.0"
      doctype-public="-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN"

And here's the relevant code:

 <!-- transform and write out the article -->
  <xsl:template match="/">
    <xsl:result-document method="xml" format="nlm-{article/@dtd-version}">

 <!-- Article Mods -->

...(other stuff not relevant to this question)...

<xsl:template match="@*|node()">
      <xsl:apply-templates select="@*|node()"/>

 <!-- 11/30/11: remove xsi namespace from <article> -->
  <xsl:template match="*">
    <xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
      <xsl:copy-of select="namespace::*[name(.)!='xsi']"/>
      <xsl:copy-of select="@*"/>

Thanks much!


Lynn Murdock, MLIS
Web Producer
Public Library of Science (PLoS)

Current Thread


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.
First Name
Last Name
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.