Subject: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:
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?
Subject: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?
Subject: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.
Subject: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?
Subject: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."