p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Adding multiple namespaces to root element (http://p2p.wrox.com/showthread.php?t=100409)

Neal December 3rd, 2019 01:28 PM

Adding multiple namespaces to root element
 
Hi,

version 1.0

I have a requirement to output a root element that contains 2 namespaces. Neither of the namespaces are contained within the input xml. The desired output is :

Code:

<Document xmlns="example:01test:02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Level1>
....
</Level1>
</Document>

How do I achieve this ?

If I select
Code:


<xsl:template match="/">
<Document xmlns="example:01test:02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Level1>
....
</Level1>
</Document>
</xsl:template>

Then just the following is output :
Code:

<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
Thanks in advance

mhkay December 3rd, 2019 02:59 PM

Your code looks perfectly correct to me.

That probably means the bug is in the part of the code that you haven't shown us... Please give a complete runnable repro, and say which XSLT processor you are using.

Neal December 4th, 2019 09:29 AM

Thanks Michael,
I'm using XMLSpy 2017 Professional. I hope I understand your reply. Here is the xslt code including referenced namespaces.

Code:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsi:schemaLocation="" xmlns:env="http://schemas.microsoft.com/dynamic...uments/Message" xmlns:mp="http://schemas.microsoft.com/dynamic...uments/Message" xmlns:ns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:date="http://exslt.org/dates-and-times"
exclude-result-prefixes="xsl env mp ns xsi date">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Level1>
....
</Level1>
</Document>
</xsl:template>
</xsl:stylesheet>

The desired output expected is:

Code:

<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Level1>
....
</Level1>
</Document>


mhkay December 4th, 2019 09:38 AM

I don't know where the namespace xmlns="example:01test:02" is supposed to come from. Your stylesheet outputs the namespace xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001 .02" as one would expect.

The xsi namespace isn't output because it is listed in exclude-result-prefixes. Perhaps this is the bug - as I suggested, it's in the part of the stylesheet that was omitted from your original post.


All times are GMT -4. The time now is 10:23 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.