XSLT -> Blank xmlns=
XSLT -> Blank xmlns="" after Transform
I'm using an XSLT to transform from one XML standard to another. The particular resulting XML standard contains a root element which is part of a namespace and a child node which is part of another namepsace.
The transform successfully reflects these namespaces but the child's child now contains a blank xmlns attribute. How can I prevent this xmlns=""???
XSLT Snippet:
<_RETURN_TO_PARTY _UnparsedName="" _StreetAddress="" _StreetAddress2="" _City="" _State="" _PostalCode="" />
Source XML:
Resulting XML:
Answer by Jim Garrison for XSLT -> Blank xmlns="" after Transform
This is happening because PRIA_DOCUMENT is in the default namespace, while its parent DOCUMENT_RECORDATION is in a non-default namespace. You must put the PRIA_DOCUMENT in the same namespace as its parent, otherwise the serializer is required to generate xmlns=""
.
. . . . .
See Michael Kay's "XSLT 2.0 and XPATH 2.0, 4th edition", page 475 where he discusses this exact situation.
Answer by alan for XSLT -> Blank xmlns="" after Transform
I found a solution that worked, though it may not have been the most efficient way to achieve the desired results.
I simply changed all literal element declarations to:
and declared the namespace. The resulting xslt is as follows:
Answer by Flynn1179 for XSLT -> Blank xmlns="" after Transform
You're re-defining the default namespace with each of those nodes with the 'xmlns=' declaration. Because the PRIA_DOCUMENT
doesn't have a namespace, the output needs to redeclare it as empty, or it would have the same namespace as it's parent. I'd recommend adding in a named namespace to those elements that have one defined, for example:
and
With these named namespaces in place, the blank declaration on the PRIA_DOCUMENT
element becomes unnecessary, and is not added.
Answer by Jazz for XSLT -> Blank xmlns="" after Transform
Put the calling template and the applied template in the same namespace.
Answer by Dan675 for XSLT -> Blank xmlns="" after Transform
I was having a similar issue even declaring the namespace on the child elements but was still ending up with
xmlns=""
I thought it was due to the xslt transformation but the string result of the transform was correct and it was when I then transformed the string to a org.w3c.dom.Document that the default namespaces were being added.
Making the DocumentBuilderFactory namespace aware fixed this
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document metadataDOM = db.parse(new ByteArrayInputStream(stringWriter.toString().getBytes()));
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment