[XSLT 1.1] xsl:document

P

Peter Gerstbach

Hello,

I need help on the new xsl:document element!
I'm using XSLT version 1.1 to be able to use the <xsl:document> element,
because I need more than 1 output files. I'm using Saxon 6.5.3

My problem is the following. My XML document is a OpenOffice-document.
There are headers and text underneath. But unfortunately the text
elements are not nested in the header elements.
See this simple example:

<h>header 1</h>
<p>text</p>
<p>text</p>
<h>header 2</h>
<p>once more text</p>
<p>and so on</p>

Now I have the folowing Problem. I want to put each header with all
subsequent text in one seperate file. To write into a new file I have to
use the "document" element as follows:

<xsl:document href="file.txt">
blahblah
</xsl:document>

So I have to write the XSLT like that:

<xsl:for-each select="h">
<xsl:document href="file.txt">
Include headers and text here...
</xsl:document>
</xsl:for-each>

But this pull-based approach is very frustrating for a very big text
document. Does anybody know how to handle this in a push-based way with
templates?

Thanks a lot!
Peter

P.S: I crossposted this question in german on de.comp.text.xml
 
D

David Carlisle

Peter Gerstbach said:
Hello,

I need help on the new xsl:document element!

Note there will never be an xsl:document element in XSL
XSL 1.1 was a working draft only and has been explictly withdrawn by the
working group (some years ago now) and will not progress to REC status.
XSLT2 drafts have a similar element but it's called (at the moment)
xsl:result-document. saxon 8 implements the xslt2 drafts.
I'm using XSLT version 1.1 to be able to use the <xsl:document> element,
because I need more than 1 output files. I'm using Saxon 6.5.3

My problem is the following. My XML document is a OpenOffice-document.
There are headers and text underneath. But unfortunately the text
elements are not nested in the header elements.
See this simple example:

<h>header 1</h>
<p>text</p>
<p>text</p>
<h>header 2</h>
<p>once more text</p>
<p>and so on</p>

Now I have the folowing Problem. I want to put each header with all
subsequent text in one seperate file. To write into a new file I have to
use the "document" element as follows:

<xsl:document href="file.txt">
blahblah
</xsl:document>

So I have to write the XSLT like that:

<xsl:for-each select="h">
<xsl:document href="file.txt">
Include headers and text here...
</xsl:document>
</xsl:for-each>

But this pull-based approach is very frustrating for a very big text
document. Does anybody know how to handle this in a push-based way with
templates?

xslt2 grouping constructs would help here but in xslt1 you can use any
of the standard grouping techniques, for example I think that you want
every node up to but not including the next h so that would be

<xsl:for-each select="h">
<xsl:document href="file-{position()}.txt">
<xsl:variable name="n" select="count(following-sibling::h)"/>
<xsl:apply-templates select=".|following-sibling::node()[count(following-sibling::h)=$n]"/>
</xsl:document>
</xsl:for-each>


Then you just need templates for uour elements doing whatever transform
you require. each section will appear in file-1.txt file-2.txt etc.

David
 
P

Peter Gerstbach

David said:
Note there will never be an xsl:document element in XSL
XSL 1.1 was a working draft only and has been explictly withdrawn by the
working group (some years ago now) and will not progress to REC status.
XSLT2 drafts have a similar element but it's called (at the moment)
xsl:result-document. saxon 8 implements the xslt2 drafts.

Ok, thank you, I will give Saxon 8 a try!
xslt2 grouping constructs would help here but in xslt1 you can use any
of the standard grouping techniques, for example I think that you want
every node up to but not including the next h so that would be

<xsl:for-each select="h">
<xsl:document href="file-{position()}.txt">
<xsl:variable name="n" select="count(following-sibling::h)"/>
<xsl:apply-templates select=".|following-sibling::node()[count(following-sibling::h)=$n]"/>
</xsl:document>
</xsl:for-each>

Yes, that's it. I was looking for a solution like this. Thanks!

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top