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 27th, 2009, 01:16 PM
Authorized User
 
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anboss
Default stable xslt code for pretty printing xml

Hi,

Can somebody Please help me with a stable xslt code for pretty printing an xml.
 
Old October 27th, 2009, 01:25 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

What is the format you want to create, HTML, PDF, something else? Do you want to use XSLT 1.0 or 2.0?
Are you aware that running XML through an XSLT stylesheet to pretty print it might lose information like XML declaration, DOCTYPE, CDATA sections?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 27th, 2009, 01:35 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try:

Code:
<xsl:stylesheet ...>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
  <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>
Or do you want something "prettier"?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old October 27th, 2009, 04:58 PM
Authorized User
 
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anboss
Default

Dear Kay,
the simple xsl you suggested didnt work in the IBM datapower environment. the output turns out to be the same as the input xml without the proper format.

To answer Martin Honnen,

What is the format you want to create, HTML, PDF, something else?

my input to the xsl is not with proper indents. the output after pretty printing should also be a formatted xml.

Do you want to use XSLT 1.0 or 2.0?
2.0

Are you aware that running XML through an XSLT stylesheet to pretty print it might lose information like XML declaration, DOCTYPE, CDATA sections?

yes i need an xslt that will take an un-formatted xml as input and outputs a formatted one.
 
Old October 28th, 2009, 07:34 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I am not familiar with IBM datapower but the suggested stylesheet with xsl:output indent="yes" should do what you want, namely take an XML document without indentation as the input and output an indented document.
If that does not do what you want then you might want to ask in a forum specific to IBM datapower.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 28th, 2009, 07:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>the simple xsl you suggested didnt work in the IBM datapower environment. the output turns out to be the same as the input xml without the proper format.

Please don't tell me that something "didn't work". Tell me what output it produced and how this differed from the output you wanted. Otherwise I can't help you any further.

One thing to add is that it might be a good idea to strip existing whitespace as well

<xsl:strip-space elements="*"/>

Of course all of this assumes that you are dealing with an XML document where whitespace is not significant.
__________________
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
NEED XSLT CODE FOR XML suji XSLT 2 February 7th, 2008 11:54 PM
xslt code for xml suji XSLT 2 February 5th, 2008 12:18 AM
Pretty nested printing with XSLT atteeela XSLT 1 August 23rd, 2007 02:07 PM
how to stable count down timer!! [email protected] JSP Basics 0 March 8th, 2006 12:47 AM
Stable Version of VWD mar0364 ASP.NET 1.0 and 1.1 Basics 4 April 12th, 2005 03:36 PM





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