xml transformation using xlst doesn't work with invalid namespace

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p align=left><font face=Arial size=2>I have to develop an application which acts as kind of middle ware to transform files from an old system (text files) to a new system (xml files) and the other way round. I will do this by xlst files to define the transformation.</font>
<p align=left> 
<p align=left>That works, basically. However, the xml files from one system use a namespace that is not valid (url does not exist). As this is an external system, I cannot change that easily, thats how I receive them.
<p align=left> 
<p align=left>Unfortunately, as long as this invalid namespace is in the xml file, the transformation doesnt work: The output file (output type = text) is empty. No error nothing. As soon as I remove the namespace, the transformation works.
<p align=left> 
<p align=left>Please find the code below:
<p align=left> 
<p align=left>First of all, the XLST. Very simple: <font color="#0000ff" size=2>
<?</font><font color="#800000" size=2>xml</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>version</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>1.0</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>encoding</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>UTF-8</font><font size=2>"</font><font color="#0000ff" size=2> ?>
<blockquote dir=ltr style="margin-right:0px
<</font><font color="#008080" size=2>xsl<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>tylesheet</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>version</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>1.0</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xmlns:xsl</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://www.w3.org/1999/XSL/Transform</font><font size=2>"</font><font color="#0000ff" size=2>>
<blockquote dir=ltr style="margin-right:0px
<</font><font color="#008080" size=2>xsl<img height=19 alt=Surprise src="http://forums.microsoft.com/MSDN/emoticons/emotion-3.gif" width=19>utput</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>method</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>text</font><font size=2>"</font><font color="#0000ff" size=2>/>
<blockquote dir=ltr style="margin-right:0px
<</font><font color="#008080" size=2>xsl:template</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>match</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>/</font><font size=2>"</font><font color="#0000ff" size=2>> </blockquote>
<</font><font color="#008080" size=2>xsl:value-of</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>select</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>/vai_object/vai_header/source_system</font><font size=2>"</font><font color="#0000ff" size=2> /> </blockquote>
</</font><font color="#008080" size=2>xsl:template</font><font color="#0000ff" size=2>> </blockquote>
</</font><font color="#008080" size=2>xsl<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>tylesheet</font><font color="#0000ff" size=2>> </font>
<p align=left> 
<p align=left>This is the XML File with the invalid Namespace in it. Converting this File results in an empty Text File: <font color="#0000ff" size=2>
<!--</font><font color="#008000" size=2>Sample XML file generated by XMLSpy v2006 rel. 3 sp1 (http://www.altova.com)</font><font color="#0000ff" size=2>-->
<</font><font color="#800000" size=2>vai_object</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xmlns</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://www.fixprotocol.org/FIXML-5-0</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xmlns:fm</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://www.fixprotocol.org/FIXML-5-0/METADATA</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xmlns:xsi</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://www.w3.org/2001/XMLSchema-instance</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>xsi<img height=19 alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif" width=19>chemaLocation</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>http://www.fixprotocol.org/FIXML-5-0
U:DatenMeSilvia3Implementation40_XSDVAO-XSD_20071102VAO.SEC_EXEC_Order_Cancel_Submit_1.0.xsd</font><font size=2>"</font><font color="#0000ff" size=2>>
<blockquote dir=ltr style="margin-right:0px
<</font><font color="#800000" size=2>vai_header</font><font color="#0000ff" size=2>>
<blockquote dir=ltr style="margin-right:0px
<</font><font color="#800000" size=2>source_system</font><font color="#0000ff" size=2>></font><font size=2>AVA</font><font color="#0000ff" size=2></</font><font color="#800000" size=2>source_system</font><font color="#0000ff" size=2>>
<</font><font color="#800000" size=2>source_environment</font><font color="#0000ff" size=2>></font><font size=2>DAVA1</font><font color="#0000ff" size=2></</font><font color="#800000" size=2>source_environment</font><font color="#0000ff" size=2>> </font></blockquote></blockquote>
<p align=left><font color="#0000ff .....(and so on)</font>
 
<p align=left>Output of above File after Translation: Empty (Should be AVA)
<p align=left> 
<p align=left>This is the XML File that works (self written): <font color="#0000ff" size=2>
?</font><font color="#800000" size=2>xml</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>version</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>1.0</font><font size=2>"</font><font color="#0000ff" size=2> </font><font color="#ff0000" size=2>encoding</font><font color="#0000ff" size=2>=</font><font size=2>"</font><font color="#0000ff" size=2>UTF-8</font><font size=2>"</font><font color="#0000ff" size=2>?>
<!--</font><font color="#008000" size=2>Sample XML file generated by XMLSpy v2006 rel. 3 sp1 (http://www.altova.com)</font><font color="#0000ff" size=2>-->
<blockquote dir=ltr style="margin-right:0px
<</font><font color="#800000" size=2>vai_object</font><font color="#0000ff" size=2>>
<blockquote dir=ltr style="margin-right:0px
<</font><font color="#800000" size=2>vai_header</font><font color="#0000ff" size=2>>
<blockquote dir=ltr style="margin-right:0px
<</font><font color="#800000" size=2>source_system</font><font color="#0000ff" size=2>></font><font size=2>AVA</font><font color="#0000ff" size=2></</font><font color="#800000" size=2>source_system</font><font color="#0000ff" size=2>>
<</font><font color="#800000" size=2>source_environment</font><font color="#0000ff" size=2>></font><font size=2>DAVA1</font><font color="#0000ff" size=2></</font><font color="#800000" size=2>source_environment</font><font color="#0000ff" size=2>> </blockquote></blockquote></blockquote>
</font><font color="#0000ff" size=2>(...and so on) </font>
<p align=left> 
<p align=left>OutPut of above File after Translation: AVA (as it should be)
<p align=left> 
<p align=left> 
<p align=left>Does anyone know how to easily remove the namespace programmatically (which is not needed after the translation) or how to avoid this behaviour?
 
<p align=left>Any help would be much appreciated!
<p align=left>Thanks
<p align=left>Benjamin
<p align=left> 

View the full article
 
Back
Top