Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > [XSLT 1.1] xsl:document

Reply
Thread Tools

[XSLT 1.1] xsl:document

 
 
Peter Gerstbach
Guest
Posts: n/a
 
      08-11-2004
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
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      08-11-2004
Peter Gerstbach <peter@_REMOVE_THIS_gerstbach.at> writes:

> 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
 
Reply With Quote
 
 
 
 
Peter Gerstbach
Guest
Posts: n/a
 
      08-11-2004
David Carlisle wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments