Unwanted namespace not being excluded
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 71
- Joined: Sat Jan 07, 2017 1:23 am
Unwanted namespace not being excluded
Hi all,
I'm doing an XML-to-XML transformation via XSLT 2.0, and a namespace declaration from my source document is appearing in my output despite my adding it to the exclude-result-prefixes list. I'm relatively new to XSLT, so I'm not sure if I've misunderstood how to use the exclude-result-prefixes attribute, or I'm using Oxygen incorrectly, or if there's a bug.
My input document is an instance of NLM Journal Publishing 3.0, which looks like this in abbreviated form:
I'm converting to an instance of JATS, and I want to remove the "atict" namespace declaration from the <article> element (and its descendants).
I'm starting with a very simple spreadsheet:
In my output, the children of <article> (<front> and <body>) both have the "atict" namespace declaration.
What am I missing?
I'm doing an XML-to-XML transformation via XSLT 2.0, and a namespace declaration from my source document is appearing in my output despite my adding it to the exclude-result-prefixes list. I'm relatively new to XSLT, so I'm not sure if I've misunderstood how to use the exclude-result-prefixes attribute, or I'm using Oxygen incorrectly, or if there's a bug.
My input document is an instance of NLM Journal Publishing 3.0, which looks like this in abbreviated form:
Code: Select all
<!DOCTYPE article PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "journalpublishing3.dtd">
<article article-type="research-article" dtd-version="3.0" xml:lang="en"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:atict="http://www.arbortext.com/namespace/atict">
<front>...</front>
<body>...</body>
</article>
I'm starting with a very simple spreadsheet:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:atict="http://www.arbortext.com/namespace/atict"
exclude-result-prefixes="atict xs"
version="2.0">
<xsl:output method="xml"/>
<xsl:template match="article">
<article article-type="research-article" xml:lang="en" dtd-version="1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:apply-templates/>
</article>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
What am I missing?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Unwanted namespace not being excluded
Hi,
"exclude-result-prefixes" applies to created element nodes. However, you're copying elements from somewhere else with xsl:copy. When using xsl:copy, "By default, the namespace nodes of the context node are automatically copied as well, but the attributes and children of the node are not automatically copied."
So, xsl:copy i's where you need to specify that you don't want the namespaces.
Regards,
Adrian
"exclude-result-prefixes" applies to created element nodes. However, you're copying elements from somewhere else with xsl:copy. When using xsl:copy, "By default, the namespace nodes of the context node are automatically copied as well, but the attributes and children of the node are not automatically copied."
So, xsl:copy i's where you need to specify that you don't want the namespaces.
Code: Select all
<xsl:template match="*">
<xsl:copy copy-namespaces="no">
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 71
- Joined: Sat Jan 07, 2017 1:23 am
Re: Unwanted namespace not being excluded
I've just realized that although the namespace I'm trying to get rid of is no longer being added to the children (front, body, etc.) of the root element (article), it's being added to the root element itself.
My updated stylesheet looks like this:
And my output has the "atict" namespace added to the <article> start tag but none of its descendants. I'm trying to banish the namespace completely, but it seems I haven't wrapped my head around one or more of these concepts.
My updated stylesheet looks like this:
Code: Select all
<xsl:template match="article">
<article article-type="research-article" xml:lang="en" dtd-version="1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:apply-templates select="*"/>
</article>
</xsl:template>
<xsl:template match="*">
<xsl:copy copy-namespaces="no">
<xsl:for-each select="@*">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Unwanted namespace not being excluded
Hi,
I don't obtain this with what you provided here. Do you still have xsl:stylesheet/@exclude-result-prefixes="atict xs"?
I don't see something in either XML source of stylesheet that would cause that namespace prefix declaration to appear.
Do you have other elements from that namespace (with the atict prefix) in the output?
If you need the element in the output to be in a different namespace than the one from the source, you cannot copy it, you must recreate it. Though this doesn't seem to be needed here. At least not from what you've shown in the XML source.
Something like:
Regards,
Adrian
I don't obtain this with what you provided here. Do you still have xsl:stylesheet/@exclude-result-prefixes="atict xs"?
I don't see something in either XML source of stylesheet that would cause that namespace prefix declaration to appear.
Do you have other elements from that namespace (with the atict prefix) in the output?
If you need the element in the output to be in a different namespace than the one from the source, you cannot copy it, you must recreate it. Though this doesn't seem to be needed here. At least not from what you've shown in the XML source.
Something like:
Code: Select all
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 71
- Joined: Sat Jan 07, 2017 1:23 am
Re: Unwanted namespace not being excluded
Ah! You're right, of course. After adding @copy-namespaces="no" to my generic template, I had removed 'atict' from @exclude-result-prefixes (and only noticed the effect recently because the <article> start tag runs off past the right margin of my Oxygen window). I put it back, and all is well.
While I have your ear, as it were, do you recommend any particular resources for learning and working with XSLT? I have Doug Tidwell's "XSLT" (2nd edition, O'Reilly) and Michael Kay's "XSLT 2.0 and XPath 2.0" (4th edition, Wrox). Both are more reference than tutorial.
While I have your ear, as it were, do you recommend any particular resources for learning and working with XSLT? I have Doug Tidwell's "XSLT" (2nd edition, O'Reilly) and Michael Kay's "XSLT 2.0 and XPath 2.0" (4th edition, Wrox). Both are more reference than tutorial.
-
- Posts: 9421
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Unwanted namespace not being excluded
Hi,
Adrian took a few days off, so to pick up the discussion, we do not have a particular tutorial recommendation for you.
We usually start the new Oxygen XML employees with this XSLT 1.0 tutorial:
http://www.zvon.org/comp/r/tut-XSLT_1.html
but they do not seem to have one available for XSLT 2.0. In time, working on various problems, looking in the XSLT specification to see what various functions to, google searching for solutions they start progressing.
You can also ask around on Stack Overflow for a good XSLT 2.0 tutorial, see what others have to say about it.
Regards,
Radu
Adrian took a few days off, so to pick up the discussion, we do not have a particular tutorial recommendation for you.
We usually start the new Oxygen XML employees with this XSLT 1.0 tutorial:
http://www.zvon.org/comp/r/tut-XSLT_1.html
but they do not seem to have one available for XSLT 2.0. In time, working on various problems, looking in the XSLT specification to see what various functions to, google searching for solutions they start progressing.
You can also ask around on Stack Overflow for a good XSLT 2.0 tutorial, see what others have to say about it.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service