xsl-list
[Top] [All Lists]

[xsl] Removing a single namespace

2011-12-11 17:39:53
Hi-

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:

Starting:
<!DOCTYPE article
  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" 
"http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd";>
<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">

Result:
<!DOCTYPE article
  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" 
"http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd";>
<article xmlns:mml="http://www.w3.org/1998/Math/MathML"; 
xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 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"
      doctype-system="&nlmpub;3.0/journalpublishing3.dtd"/>

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}">
      <xsl:apply-templates/>
    </xsl:result-document>
  </xsl:template>

 <!-- Article Mods -->

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

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

 <!-- 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="@*"/>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>


Thanks much!

Lynn


Lynn Murdock, MLIS
Web Producer
Public Library of Science (PLoS)
http://www.plos.org



--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>