XSL paginator problem

Discussion in 'XML' started by =?ISO-8859-2?Q?=A3ukasz?=, Sep 2, 2004.

  1. Hello,
    i've short question. How convert this XML:
    <doc>
    <t1>
    ...
    <t1>
    <page-break/>
    <t2>
    ...
    <t2>
    </doc>

    into this:
    <doc>
    <page>
    <t1>
    ...
    <t1>
    </page>
    <page>
    <t2>
    ...
    <t2>
    </page>
    </doc>

    please help!
    Luke
    =?ISO-8859-2?Q?=A3ukasz?=, Sep 2, 2004
    #1
    1. Advertising

  2. =?ISO-8859-2?Q?=A3ukasz?= () wrote:
    : Hello,
    : i've short question. How convert this XML:
    : <doc>
    : <t1>
    : ...
    : <t1>
    : <page-break/>
    : <t2>
    : ...
    : <t2>
    : </doc>

    : into this:
    : <doc>
    : <page>
    : <t1>
    : ...
    : <t1>
    : </page>
    : <page>
    : <t2>
    : ...
    : <t2>
    : </page>
    : </doc>

    : please help!
    : Luke

    in perl

    s% <doc> % <doc><page> %x;
    s% </doc> % </page></doc %x;

    s% <page-break/> % </page><page> %x;

    presumably a similar simple manipulation could be done with xlst, though I
    need to read the manual for that which I don't intend to do here.
    Malcolm Dew-Jones, Sep 2, 2004
    #2
    1. Advertising

  3. =?ISO-8859-2?Q?=A3ukasz?=

    Marrow Guest

    Hi Luke,

    Try something like...

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="xml" indent="yes"/>
    <xsl:template match="doc">
    <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="page-break"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="doc/page-break">
    <page>
    <xsl:variable name="this-id" select="generate-id()"/>
    <xsl:apply-templates
    select="preceding-sibling::node()[generate-id(following-sibling::page-break)
    = $this-id]"/>
    </page>
    <xsl:if test="not(following-sibling::page-break)">
    <page>
    <xsl:apply-templates select="following-sibling::node()"/>
    </page>
    </xsl:if>
    </xsl:template>

    <xsl:template match="*">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="@* | text() | comment() | processing-instruction()">
    <xsl:copy/>
    </xsl:template>
    </xsl:stylesheet>


    HTH
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator


    "£ukasz" <> wrote in message
    news:ch7c79$rni$...
    > Hello,
    > i've short question. How convert this XML:
    > <doc>
    > <t1>
    > ...
    > <t1>
    > <page-break/>
    > <t2>
    > ...
    > <t2>
    > </doc>
    >
    > into this:
    > <doc>
    > <page>
    > <t1>
    > ...
    > <t1>
    > </page>
    > <page>
    > <t2>
    > ...
    > <t2>
    > </page>
    > </doc>
    >
    > please help!
    > Luke
    Marrow, Sep 3, 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. Kevin Flood
    Replies:
    0
    Views:
    1,017
    Kevin Flood
    Sep 8, 2004
  2. Kevin Flood
    Replies:
    1
    Views:
    2,730
    Kevin Flood
    Sep 13, 2004
  3. Klaus Friese
    Replies:
    0
    Views:
    467
    Klaus Friese
    Nov 22, 2004
  4. Replies:
    1
    Views:
    3,598
    A. Bolmarcich
    May 27, 2005
  5. Tim
    Replies:
    3
    Views:
    107
Loading...

Share This Page