XSL paginator problem

  • Thread starter =?ISO-8859-2?Q?=A3ukasz?=
  • Start date
?

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

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
 
M

Malcolm Dew-Jones

=?ISO-8859-2?Q?=A3ukasz?= ([email protected]) 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.
 
M

Marrow

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
 

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,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top