Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old October 13th, 2010, 06:27 PM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question No XML Document Declaration Line

I have a problem with an xml document created with an xml style sheet generated from an xml schema. There is nothing syntactically wrong with the xml document. The problem is the receiving system has a custom written parser that is looking for the first item in the file to have the string "<WORKORDER>". Since I generated the file using a standard xslt style sheet, I needed to declare some namespaces, it looks as below:

<?xml version="1.0" encoding="US-ASCII"?>
<WORKORDER xmlns="http://www.comp.com/file/94x/app"
xmlns:e="http://www.comp.com/file/94x/app"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<WO-DATE>20101012</WO-DATE>
<WO-TIME>194142</WO-TIME>
<GFN>unisys_eod</GFN>
<FULLNAME>unisys_eod1006</FULLNAME>
<CAT-DATE>20101006</CAT-DATE>
<CAT-TIME>175541</CAT-TIME>
</WORKORDER>


Restating they want the file with no document declaration and no attributes starting as:

<WORKORDER>
...
</WORKORDER>

I found in combination with Mike Kay's XSLT P.R. book and through this site how to specify that there be no namespace attributes using "exclude-result-prefixes="xsl xsd e #default"". Thanks, both great resources.

Is there a method within XSLT to request that be no xml document declaration line?

Thanks.
Using Xalan version 1.3
 
Old October 13th, 2010, 06:47 PM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Smile omit-xml-declaration="yes"

I found the solution through web searches. The method is to declare the omit-xml-declaration="yes" attribute on the xsl:output element.
Thanks for this site.
 
Old October 14th, 2010, 03:17 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

My advice would be to push to have them use an XML parser, a custom one that doesn't support the spec is just wrong and fudging results to comply just propagates bad practice even, as in this case, it can be done. There's little excuse nowadays for consuming XML using string parsing techniques.

And the two results are different:
Code:
<WORKORDER xmlns=http://www.comp.com/file/94x/app />
is not the same as
Code:
<WORKORDER />
as the first WORKORDER element is in a namespace whereas the second isn't. This means that using exclude-result-prefixes shouldn't work as it won't remove an actively used namespace declaration.
I will have to experiment, I've never used the #default or #all values.
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Split xml file with result document and javax.xml.transform.Transformer. nisargmca XSLT 3 January 12th, 2010 06:26 AM
xml declaration not displayed zsheema XSLT 10 May 15th, 2008 04:36 AM
xml declaration chroniclemaster1 XML 0 September 20th, 2007 02:00 PM
omit-xml-declaration dextermagnific XSLT 3 August 4th, 2006 09:55 AM
Create XML Doc with Stylesheet Declaration rodmcleay General .NET 1 November 15th, 2004 04:11 AM





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