XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Max MandersSubject: Change structure of output document
Author: Max Manders
Date: 14 May 2007 05:17 AM
Originally Posted: 14 May 2007 05:16 AM
I am working with a fairly complex valid XML document. I am trying to use XSLT and XSL-FO together with FOP to convert this document into a human readable PDF document. However, I would like to change the order of some of the elements.

Currently, my document has a form similar to this (I have simplified this and probably shouldn't use actual tag names as I work for local government).
Code:

<article>
<a>Lorem</a>
<b>Ipsum</b>
<c>
<d>Dolor</d>
<e>
<f>Amet</f>
</e>
</c>
<f>The</f>
<g>Quick</g>
<h>
<i>Brown</i>
<j>
<k>Fox</k>
</j>
</h>
<l>jumps</l>
<m>over</m>
</article>

You can see that this excerpt consists of a number of 'atomic' text only nodes, and a number of more complex subtrees. I would like to rewrite each <articles> element so that the simple text only nodes are output first, and then each of the subtrees are output at the end. I have captured the simple text nodes using a template that matches
Code:

article/*[not(*)]

And I have captures the more complex subtrees using a tempalte that matches the name of the root tag, i.e.<c> and <h> above. However, when I use these templates, the subtrees are output in document order as they appear, i.e. <c> between <b> and <f>.

Can anyone suggest how I could write a template(s) that would allow me to output the subtrees after the simple text nodes?

Many Thanks.

Max

Postnext
Elias HuterSubject: Change structure of output document
Author: Elias Huter
Date: 14 May 2007 06:18 AM
Would that be your desired result?

<article>
<a>Lorem</a>
<b>Ipsum</b>
<f>The</f>
<g>Quick</g>
<l>jumps</l>
<m>over</m>
<c>
<d>Dolor</d>
<e>
<f>Amet</f>
</e>
</c>
<h>
<i>Brown</i>
<j>
<k>Fox</k>
</j>
</h>
</article>

Postnext
Elias HuterSubject: Change structure of output document
Author: Elias Huter
Date: 14 May 2007 06:33 AM
If so, try this one.


Documentsort.xsl

Postnext
Max MandersSubject: Change structure of output document
Author: Max Manders
Date: 14 May 2007 06:55 AM
Yup - that's the output structure I'm looking for. I'm having a little trouble understanding your stylesheet though... Would I have to apply this stylesheet first, and then once I have this new tree structure, apply my xsl-fo sheet?

Postnext
Elias HuterSubject: Change structure of output document
Author: Elias Huter
Date: 14 May 2007 07:30 AM
I guess you currently have one "for-each article" loop. This loop is now replaced by two "for-each article" loops. The first one gets all nodes without childs, the second one all nodes with childs.

Postnext
Max MandersSubject: Change structure of output document
Author: Max Manders
Date: 14 May 2007 08:22 AM
Ah, unfortunately no I'm not using any for-each iterations. I'm using a purely declarative approach. I tried using for-each but found that I had problems with the context node not changing, and as such my XPath expressions were horendous, i.e. */*/*/element[*[not(*) and name(..)='some_other_element'

can this be done without using for-each? And again, would a two step process be involved: once to reorder the xml, then second to format using xsl-fo?

Posttop
Elias HuterSubject: Change structure of output document
Author: Elias Huter
Date: 15 May 2007 03:54 AM
I'm sorry, I'm not working with XSL-FO maybe someone else can answer this.

I also don't see a solution with the declarative approach (certainly because I never solved a bigger project with this way ...), but you can try to mix the two solutions! I can't see a reason why you shouldn't use a for each within a "match template".


But like Tony said:

"General XSLT questions are best asked on the xsl-list run by
Mulberry Technologies. There experts with varied experiences
are often eager to help."

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.