wood burning stoves*
The moose likes XML and Related Technologies and the fly likes XSL Sorting Output Formatting Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSL Sorting Output Formatting Issue" Watch "XSL Sorting Output Formatting Issue" New topic
Author

XSL Sorting Output Formatting Issue

Josefina Smith
Greenhorn

Joined: Aug 03, 2013
Posts: 5
Hi All,

So I have a small java program that uses an XSL template to sort an incoming XML document. (only the OrderLine elements in the below example are sorted, the sort itself is working great)
Also, it is sorting based on the OrderLine attributes: IsHazmat="Y" (first) number="S-3" (second)

Input XML Document:

-- below

XSL Template:




Output XML Document:




As you can see, the formatting is off a little making the output XML document look messy.
My goal, is to take the Input document and produce an Output document that looks exactly like the Input document except with the sort applied.

Do you guys have any tips that will make an Output XML format nicely?

thank you,

Josefina

Josefina Smith
Greenhorn

Joined: Aug 03, 2013
Posts: 5
appologies, I posted incorrect input XML doc, here is the input doc:

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I have to say, I don't quite understand your transformation. It seems to be looking for OrderLine elements, and there aren't any such elements in the document you said was your input. But anyway, your problem is that you need to manage the whitespace you're sending to the output with that transformation. Here's a couple of links you might read:

Tip: Control white space in an XSLT style sheet

Chapter 4. Creating Output > Dealing with Whitespace
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
<xsl:apply-templates select="OrderLine">
<xsl:sort select="@IsHazmat" order="descending"/>
<xsl:sort select="substring-after(@number,'-')" order="ascending" data-type="number"/>
</xsl:apply-templates>

Apart from possible mixed up OrderLine and mailbox (but not only, far from that, the template OrderLine cannot be corrected by only changing name back to mailbox...) this xsl:sort line cannot be correct. It should look at least like this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSL Sorting Output Formatting Issue
 
Similar Threads
removing duplicate elements
Using XSLT, how do I copy nodes, tags and all?
Unnecessary Tags
HTML tag within XML
Need help with XSLT, modifying XML config files.