Re: [xsl] conditional multiple outputs

Subject: Re: [xsl] conditional multiple outputs
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 14 May 2009 12:17:31 +0100
 <xsl:result-document generates a complete file not appends to an
 existing file so the process stops  on the third title as it tries to
 write file2 again.

You shoult think of the external  file as like an element if your
desired end result had been

                  <title>file 1 xxx </title>
                <title>file 1 abc </title>
                <title>file 2 efg </title>
                <title>file 2 xxx </title>
                <title>file 2 zzz </title>
                <title>file 2 ihk </title>
                <title>file 3 abc </title>
                <title>file 3 xyz </title>

You would not, in xslt have tried to append to the child nodes of file2
in different templates, you would have opened file2, then generated
using an xpath that selected the right titles all the relevant entries
then closed the element.

You need to treat xsl:result document in exactly the same way.

somethinng like

<xsl:for-each-group select="group/title"
<xsl:result-document href="file{current-grouping-key()}.xml">
 <xsl:for-each select="current-group()">
   <xsl:value-of select="."/>

Incidentally it's usually better to do
<xsl:value-of select="."/>
rather than
<xsl:value-of select="./text()"/>
the ./ at the front doesn't do anything so ./text() is equivalent to
<xsl:value-of select="text()"/>
which doesn't ignore for example comments in the input in the way you
might expect (they will get translated to spaces, effectively).


The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 

Current Thread