0

I create a JSON object in my XSLT stylesheet. It's difficult to read by eye when viewing the HTML source. I'm wondering if there's a way in my XSLT template to cause a visual line break so each {...}, is on a new line. It would make it so much easier to read by eye...

Currently:

[{ .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }, { .... }]

Desired:

[
{ .... }, 
{ .... }, 
{ .... }, 
{ .... }, 
etc., etc.
]

I'm not sure what to do in XSLT that would cause the break and then I'm sure there is something JSON requires for the break to be valid?

rwkiii
  • 5,716
  • 18
  • 65
  • 114

2 Answers2

1

When I used xslt > 5 yrs ago I used to achieve whitespaces with <xsl:output method="text"/>

http://msdn.microsoft.com/en-us/library/ms256187.aspx

Hope this helps!

mortb
  • 9,361
  • 3
  • 26
  • 44
  • I'm not sure, but I think that would force me to manually format most of my stylesheet? I've got output method set to html right now and most of my page is cleanly formatted. My JSON string is created in an `xsl:for-each` and creates a fairly large paragraph all ran together. I get by, but it would speed things up for me when I need to look at data if I could make each element of the JSON array start on a new line. – rwkiii Jun 29 '12 at 13:09
  • Thank you for that reference. I tried everything there with no success. Apparently I have to set my output method to text in order for those ideas to work. I tried that, but then my web page displays all of the XSLT output as text. XSLT can be stubborn a lot. :S – rwkiii Jun 29 '12 at 14:03
  • Yes, xslt is hard to work with. For the basic case it is ok, but whenever you go into details (which you have to do sooner or later) it can be a pain... – mortb Jun 29 '12 at 14:15
1

Use at the right place in your code:

<xsl:text>&#xA;</xsl:text>
Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431