user49758
user49758

Reputation: 51

XML and XSL with unwanted namespace when using saxon

I have used exclude-result-prefixes="ae" in the xsl stylesheet. Then also namespace is present in the converted XML file. I'm using saxon parser. Please find my MWE below:

My XML file is :

<?xml version="1.0" encoding="UTF-8"?>
<ArticleInfo Language="En" ContainsESM="No" OutputMedium="All">
<ArticleID>034</ArticleID>
<ArticleJID>BMCL</ArticleJID>
<ArticleDOI>10.1000/j.asdf.2015.02.034</ArticleDOI>
<ArticleTitle>Sample Article Title with &#x2015; unicode value</ArticleTitle>
<Para>Sample Paragraph text here</Para>
</ArticleInfo>

and My XSL file is :

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ae="www.ams.org" exclude-result-prefixes="ae" version="3.0">

<xsl:output omit-xml-declaration="no" indent="yes" method="xml"/>

<xsl:strip-space elements="*"/>

<xsl:template match="/">
<xsl:text disable-output-escaping="yes">
&lt;!DOCTYPE article PUBLIC "-//AMS//DTD journal article//EN//XML" "art.dtd"&gt;
</xsl:text>  
<xsl:apply-templates/>
</xsl:template>

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

<xsl:variable name="ElsDoi" select="/ArticleInfo/ArticleDOI"/>

<xsl:template match="ArticleInfo">
<ae:doi><xsl:value-of select="$ElsDoi"/></ae:doi>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="Para">
  <xsl:element name="ae:para">
    <xsl:apply-templates select="@* | node()"/>
  </xsl:element>
</xsl:template>
</xsl:stylesheet>

I'm Getting output XML file is :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//AMS//DTD journal article//EN//XML" "art.dtd">
<ae:doi xmlns:ae="www.ams.org">10.1000/j.asdf.2015.02.034</ae:doi>
<ArticleID>034</ArticleID>
<ArticleJID>BMCL</ArticleJID>
<ArticleDOI>10.1000/j.asdf.2015.02.034</ArticleDOI>
<ArticleTitle>Sample Article Title with ― unicode value</ArticleTitle>
<ae:para xmlns:ae="www.ams.org">Sample Paragraph text here</ae:para>

Expecting output XML file is :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//AMS//DTD journal article//EN//XML" "art.dtd">
<ae:doi>10.1000/j.asdf.2015.02.034</ae:doi>
<ArticleID>034</ArticleID>
<ArticleJID>BMCL</ArticleJID>
<ArticleDOI>10.1000/j.asdf.2015.02.034</ArticleDOI>
<ArticleTitle>Sample Article Title with ― unicode value</ArticleTitle>
<ae:para>Sample Paragraph text here</ae:para>

Please note unwanted xmlns:ae="www.ams.org" is present in the output XML file and also in title &#x2015 is converted to unicode symbol. How do avoid this.

Upvotes: 1

Views: 366

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167401

With <xsl:element name="ae:para"> you are explictly creating an element in the namespace bound to the prefix ae so don't expect exclude-result-prefixes to exclude that namespace as it is only useful to avoid namespace declarations of unused namespaces. A namespace used in a node name can't be excluded with exclude-result-prefixes, as otherwise the result would not be namespace well-formed XML.

Upvotes: 1

Related Questions