Subject: Re: [xsl] Generating "nested" Result Documents From Flat Source|
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 04 Oct 2010 22:17:26 +0100
I have a transform that converts Word docs into sets of result documents. My general technique is to pre-process the Word into a sequence of elements annotated with the effective result level, defining the result hierarchy the elements should generate.
Given this I can then use for-each-group group-starting-with to translate the flat list into the appropriate hierarchy via essentially recursive descent (that is, each level applies processing for the next level down to the current group in the for-each).
However, I'm running into a problem when I have the case where a group at level 1 and a group at level 2 both need to generate result documents.
So for example, I might have this Word input:
Heading 1 Normal Heading 2 Normal Heading 1 Normal
Where the desired result is three result documents, one for the first Heading 1 paragraph and the Normal paragraph following it, one for the Heading 2 and its following para and one for the last Heading 1.
In addition, I currently have the code written to apply at least two passes of processing over the elements that will eventually be put into a document, e.g.:
<xsl:variable name="resultDoc"> <xsl:apply-templates select="current-group()" mode="pass-one"/> </xsl:variable>
<xsl:result-document href="..."> <xsl:apply-templates select="$resultDoc" mode="pass-two"/> </xsl:result-document>
This works fine for one level of output (that is, a single result document generated by highest group).
But if I have a nested group that also needs a result document as in the example above then I get the failure "Cannot switch to a final result destination while writing a temporary tree" which I guess makes sense (or at least I accept that there must be a good reason for this restriction). This is because the processing happening in mode "pass-one" may hit the part shown above, meaning the processor is currently in the process of constructing the value of "resultDoc" for the higher-level group.
I've puzzled over this problem and I'm not seeing an obvious solution but I suspect that there's some relatively simple approach that would allow me to generate multiple result documents.
The only thing that I've thought of so far is to have the main processing logic generate a sequence of elements that I can process serially to generate the required result documents.
Am I missing some non-obvious algorithm?
for-each-group group-starting-with="heading1" for-each-group group-starting-with="heading2" /for-each-group /for-each-group
for-each-group group-starting-with="heading1|heading2" ... /for-each-group