Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 3rd, 2019, 01:28 PM
Friend of Wrox
Points: 718, Level: 10
Points: 718, Level: 10 Points: 718, Level: 10 Points: 718, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default 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
__________________
Neal

A Northern Soul
  #2 (permalink)  
Old December 3rd, 2019, 02:59 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
  #3 (permalink)  
Old December 4th, 2019, 09:29 AM
Friend of Wrox
Points: 718, Level: 10
Points: 718, Level: 10 Points: 718, Level: 10 Points: 718, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default

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>
__________________
Neal

A Northern Soul
  #4 (permalink)  
Old December 4th, 2019, 09:38 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding the namespaces using XSLT sivakumar_g01 XSLT 5 October 29th, 2010 07:37 AM
I used default namespace in my stylesheet but root element is not firing smandeh XSLT 2 June 9th, 2010 09:22 PM
What is the best approch to find root element ? nisargmca XSLT 5 March 11th, 2010 07:25 AM
Chapter 7 re hiding root element in TreeView control stephjnca BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 May 27th, 2009 02:26 PM
root element missing Kross Classic ASP Basics 1 February 5th, 2007 08:16 AM





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