Xalan inserts spurious xmlns attributes in elements with targetNamespace attributes -----------------------------------------------------------------------------------
Key: XALANJ-2518 URL: https://issues.apache.org/jira/browse/XALANJ-2518 Project: XalanJ2 Issue Type: Bug Security Level: No security risk; visible to anyone (Ordinary problems in Xalan projects. Anybody can view the issue.) Components: Xalan Affects Versions: 2.7.1 Environment: Observed on RedHat 5.1 and Windows XP. Reporter: Jason Walton Under certain conditions, when Xalan encounters a element with a targetNamespace but no "xmlns" attribute, it will add an xmlns attribute even if the attribute is not required. The following example (which is a simple XSLT to change the default namespace of an XML document) demonstrates the problem: Input: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <root xmlns="http://www.alcatel-lucent.com/1"> <xsd:schema xmlns:a="http://www.alcatel-lucent.com/schema-a" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.alcatel-lucent.com/schema-a"> <xsd:complexType name="MyType"> <xsd:complexContent> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> </xsd:sequence> </xsd:complexContent> </xsd:complexType> <xsd:element name="element" type="a:MyType"/> </xsd:schema> <testElementFromNs1/> </root> XSLT: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://www.alcatel-lucent.com/1" xmlns="http://www.alcatel-lucent.com/2" version="1.0" exclude-result-prefixes="ns1"> <xsl:output method="xml" indent="yes"/> <!-- Copy all objects and their contents --> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*" /> </xsl:copy> </xsl:template> <!-- Copy all objects from ns1, but change their namespace to the new namespace. By only using the local name of the element, we effectively assign it to the "xmlns=" namespace declared in the document's root node. --> <xsl:template match="ns1:*"> <xsl:element name="{local-name()}"> <xsl:apply-templates select="node()|@*"/> </xsl:element> </xsl:template> </xsl:stylesheet> The output "xsd:schema" element will have 'xmlns="http://www.alcatel-lucent.com/1"' added to its list of attributes (especially strange since no child elements reference the namespace, and the namespace is the "old" namespace). In our application this is causing problems because we have a schema embedded as part of a configuration file. When we try to run the configuration file through an XSLT, these extra xmlns attributes are added to various schema elements. When we later try to extract the schema, the extra xmlns attributes are not necessarily understood by the client trying to use the schema. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: xalan-dev-unsubscr...@xml.apache.org For additional commands, e-mail: xalan-dev-h...@xml.apache.org