473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

[XSLT 1.1] xsl:document

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
Jul 20 '05 #1
2 3174
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
Jul 20 '05 #2
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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniel | last post by:
how to make sure a xsl document has valid xsl syntax? i tried loading it into an xml document but that doesnt show syntax errors inside attributes such as "foo/bar" vs "bar\foo"
1
by: Daniel | last post by:
in C# how do i transform an xml document with an xsl document when my xml document is a string and my xsl document is a string? the msdn examples only show how to do it with steams and files. in my...
2
by: FrankStallone | last post by:
I am just getting started in XML and I made my first xml, dtd and xslt file and XML spy said they were all valid and they worked. This was the xslt doc that worked. <?xml version="1.0"...
4
by: Asbjørn Ulsberg | last post by:
Sorry for posting to a lot of groups, but I'm not sure what this problem relates to, so I thought it was better to be safe than sorry. Please feel free to set FUT to the proper group when...
1
by: news.microsoft.com | last post by:
I am writing an XSL file to load a node set with XSL document() function with the syntax as follows: <xsl:variable name="var1" select="document('..\res\xmlfile.xml')/Accounts"/> Unfortunately it's...
1
by: Daniel | last post by:
in C# how do i transform an xml document with an xsl document when my xml document is a string and my xsl document is a string? the msdn examples only show how to do it with steams and files. in my...
4
by: dar_imiro | last post by:
Hi, I'm trying to get rid of frames as menu holder in my html-page. I'd also like to separate the menu structure to xml and xslt. Also the actual content is divided to xml and its corresponding...
1
by: David | last post by:
First of all, yes we are still using classic ASP, lol. I have a XSL document that is reading in info from a XML file. I have to display serveral server side dates on the page. Is there anyway to...
2
by: mdawg | last post by:
I am attempting to use the XSLT document function to extract the value of an attribute in a secondary XML file. In order to add an image to the generatedHTML Both xml files I am dealing with are...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.