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

October 27th, 2009, 01:16 PM
|
|
Authorized User
|
|
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
stable xslt code for pretty printing xml
Hi,
Can somebody Please help me with a stable xslt code for pretty printing an xml.
|
|

October 27th, 2009, 01:25 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

October 27th, 2009, 01:35 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

October 27th, 2009, 04:58 PM
|
|
Authorized User
|
|
Join Date: May 2008
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

October 28th, 2009, 07:34 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

October 28th, 2009, 07:51 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>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
|
|
 |