[XSLT 1.1] xsl:document

Discussion in 'XML' started by Peter Gerstbach, Aug 11, 2004.

  1. 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
     
    Peter Gerstbach, Aug 11, 2004
    #1
    1. Advertising

  2. 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
     
    David Carlisle, Aug 11, 2004
    #2
    1. Advertising

  3. 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
     
    Peter Gerstbach, Aug 11, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vijay singh
    Replies:
    1
    Views:
    438
    Martin Honnen
    Nov 4, 2004
  2. Replies:
    1
    Views:
    3,622
    A. Bolmarcich
    May 27, 2005
  3. Replies:
    4
    Views:
    684
  4. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help with XSL/XSL:FO for producing revision indicator bar in document.

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Apr 28, 2006, in forum: XML
    Replies:
    6
    Views:
    577
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    May 3, 2006
  5. sqad
    Replies:
    1
    Views:
    3,583
Loading...

Share This Page