Re: [xsl] Can't solve the following XSL transformation

Subject: Re: [xsl] Can't solve the following XSL transformation
From: John Robb <john_ok@xxxxxx>
Date: Mon, 25 Jul 2005 13:02:07 +0300
And what will be the xx-namespace for MSXML 3.0(MSXML 4.0)?
Mon, 25 Jul 2005 10:51:24 +0100, "Michael Kay" <mike@xxxxxxxxxxxx> ohq`k(`):


There are two ways of doing a two-pass transformation

(a) use two stylesheets, saving the result of the first one in a temporary
file


(b) use a single stylesheet, with the structure

<xsl:variable name="temp">
 <xsl:apply-templates select="/" mode="phase1"/>
</xsl:variable>

<xsl:template match="/">
<xsl:apply-templates select="xx:node-set($temp)" mode="phase2"/>
</xsl:template>


Then label all the templates used during phase 1 with mode="phase1", and
similarly for phase2. The xx:node-set() function is needed with XSLT 1.0
processors but not with XSLT 2.0, and the namespace xx: depends on the
processor you are using.


Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: John Robb [mailto:john_ok@xxxxxx] Sent: 25 July 2005 10:46
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Can't solve the following XSL transformation


In the algorithm you mentioned about the second pass.What did you mean and where to save the tree from the first pass?

Mon, 25 Jul 2005 10:35:17 +0100, "Michael Kay" <mike@xxxxxxxxxxxx> ohq`k(`):

> You just generalize the solution I gave you. Instead of using >"@lines" as a
> specific attribute, you have to use count(*) or something similar to >count
> how many child elements there are.
> > Michael Kay
> http://www.saxonica.com/ > >> -----Original Message-----
>> From: John Robb [mailto:john_ok@xxxxxx] >> Sent: 25 July 2005 09:13
>> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> Subject: Re: [xsl] Can't solve the following XSL transformation
>> >> But how is it possible to determine,if the following Subsector can >>be >> shown on this page or on the following.The problem is how to output >> page-breaks exactly before sector/subsector only and no more than 25 >> elements per pag.
>> >> Mon, 25 Jul 2005 07:31:26 +0100, "Michael Kay" <mike@xxxxxxxxxxxx> >> ohq`k(`):
>> >> > Here's a simplified form of the problem. Given this input:
>> > >> > <chap>
>> > <para lines="3"/>
>> > <para lines="5"/>
>> > <para lines="8"/>
>> > etc
>> > </chap>
>> > >> > produce a copy of the input, with a <page-break/> element inserted >> >after any
>> > para that causes the cumulative number of lines to exceed 30.
>> > >> > The answer to this is what I call "sibling recursion", something >> >like this:
>> > >> > <xsl:template match="chap">
>> > <xsl:copy>
>> > <xsl:apply-templates select="para[1]"/>
>> > </xsl:copy>
>> > </xsl:template>
>> > >> > <xsl:template match="para">
>> > <xsl:param name="lines-so-far" select="0"/> <!-- 0 is the >>default >> >value
>> > of the parameter -->
>> > <xsl:copy-of select="."/>
>> > <xsl:choose>
>> > <xsl:when test="$lines-so-far + @lines <= 30">
>> > <xsl:apply-templates select="following-sibling::para[1]">
>> > <xsl:with-param name="lines-so-far" select="$lines-so-far + >> >@lines"/>
>> > </xsl:apply-templates>
>> > </xsl:when>
>> > <xsl:otherwise>
>> > <page-break/>
>> > <xsl:apply-templates select="following-sibling::para[1]"/>
>> > </xsl:otherwise>
>> > </xsl:choose>
>> > </xsl:template>
>> > >> > Sibling recursion using xsl:apply-templates has a couple of >> >advantages over
>> > call-template recursion: the sequence over which you are iterating >> >is an
>> > implicit parameter (it's identified implicitly by the >> context node); >> >and the
>> > recursion terminates naturally when there are no more siblings.
>> > >> > Michael Kay
>> > http://www.saxonica.com/
>> > >> > >> >> -----Original Message-----
>> >> From: John Robb [mailto:john_ok@xxxxxx] >> >> Sent: 25 July 2005 06:22
>> >> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> >> Subject: Re: [xsl] Can't solve the following XSL transformation
>> >> >> >> I'm a novice in XSLT and it's not very easy for me to realize the >> >> second part of the algorithm.Can you please give me a >> short example.
>> >> Thank you in advance.
>> >> >> >> Sun, 24 Jul 2005 23:26:09 +0100, "Michael Kay" >><mike@xxxxxxxxxxxx> >> >> ohq`k(`):
>> >> >> >> > The first stage is a classical grouping problem: see
>> >> > http://www.jenitennison.com/xslt/grouping for advice on using >> >> >Muenchian
>> >> > grouping in XSLT 1.0, or use the new xsl:for-each-group >> >>instruction >> >> >in 2.0.
>> >> > (Note, XSLT 1.1 doesn't really exist, it was a working >> draft that >> >> >wasn't
>> >> > followed up).
>> >> > >> >> > Insert the page breaks in a second pass through the >> data. This is >> >>a >> >> >little
>> >> > tricky (I use it as an exercise on courses) and requires >> >>processing >> >> >the
>> >> > sequence using recursion, passing a parameter in the recursive >> >>call >> >> >that
>> >> > indicates the number of lines processed so far.
>> >> > >> >> > Michael Kay
>> >> > http://www.saxonica.com/
>> >> > >> >> >> -----Original Message-----
>> >> >> From: John Robb [mailto:john_ok@xxxxxx] >> >> >> Sent: 24 July 2005 22:45
>> >> >> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>> >> >> Subject: [xsl] Can't solve the following XSL transformation
>> >> >> >> >> >> I'm a novice in XSLT and doesn't have any experience.Can >> >> you help me >> >> >> to perform the following transformation:
>> >> >> trasformed data should look as follows:
>> >> >> >> >> >> ****************
>> >> >> Sector 1
>> >> >> ****************
>> >> >> Subsector 1
>> >> >> ++++++++++++++++
>> >> >> ID[t]Value
>> >> >> ----------------
>> >> >> id1[t]value1
>> >> >> ...
>> >> >> idN valueN
>> >> >> ----------------
>> >> >> Subsector 2
>> >> >> ++++++++++++++++
>> >> >> ID[t]Value
>> >> >> ----------------
>> >> >> id1[t]value1
>> >> >> ...
>> >> >> idN valueN
>> >> >> ...
>> >> >> ****************
>> >> >> Sector 2
>> >> >> ****************
>> >> >> Subsector 1
>> >> >> ++++++++++++++++
>> >> >> ID[t]Value
>> >> >> ----------------
>> >> >> id1[t]value1
>> >> >> ...
>> >> >> idN valueN
>> >> >> ----------------
>> >> >> Subsector 2
>> >> >> ++++++++++++++++
>> >> >> ID[t]Value
>> >> >> ----------------
>> >> >> id1[t]value1
>> >> >> ...
>> >> >> idN valueN
>> >> >> ...
>> >> >> >> >> >> There is a limitation: no more than 25 data rows (idX >> valueX) per >> >> >> page.Page breaks (<span style="page-break-before: >> >>always"></span>) >> >> >> cannot be inserted in the middle of data section but before >> >> >> sector/subsector only.I'm using XSLT v1.1.
>> >> >> Here is the xml:
>> >> >> <?xml version="1.0" encoding="iso-8859-1" ?>
>> >> >> <data>
>> >> >> [t]<item id="i1"[t]sector="s1"[t]subsector="u1">561</item>
>> >> >> [t]<item id="i10"[t]sector="s3"[t]subsector="u4">15</item>
>> >> >> [t]<item id="i22"[t]sector="s2"[t]subsector="u2">1234</item>
>> >> >> [t]<item id="i11"[t]sector="s1"[t]subsector="u2">123</item>
>> >> >> [t]<item id="i17"[t]sector="s1"[t]subsector="u3">165</item>
>> >> >> [t]<item id="i61"[t]sector="s2"[t]subsector="u1">346</item>
>> >> >> [t]<item id="i12"[t]sector="s2"[t]subsector="u5">3425</item>
>> >> >> [t]<item id="i2"[t]sector="s3"[t]subsector="u4">78</item>
>> >> >> [t]<item id="i14"[t]sector="s3"[t]subsector="u4">51</item>
>> >> >> [t]<item id="i21"[t]sector="s1"[t]subsector="u5">346</item>
>> >> >> [t]<item id="i39"[t]sector="s3"[t]subsector="u2">463</item>
>> >> >> [t]<item id="i44"[t]sector="s2"[t]subsector="u3">151</item>
>> >> >> [t]<item id="i89"[t]sector="s1"[t]subsector="u1">451</item>
>> >> >> [t]<item id="i81"[t]sector="s2"[t]subsector="u4">771</item>
>> >> >> [t]<item id="i36"[t]sector="s2"[t]subsector="u5">5654</item>
>> >> >> [t]<item id="i27"[t]sector="s3"[t]subsector="u3">362</item>
>> >> >> [t]<item id="i15"[t]sector="s1"[t]subsector="u5">234</item>
>> >> >> [t]<item id="i18"[t]sector="s3"[t]subsector="u2">73</item>
>> >> >> [t]<item id="i51"[t]sector="s3"[t]subsector="u5">567</item>
>> >> >> [t]<item id="i26"[t]sector="s1"[t]subsector="u4">17</item>
>> >> >> [t]<item id="i95"[t]sector="s3"[t]subsector="u5">67489</item>
>> >> >> [t]<item id="i13"[t]sector="s1"[t]subsector="u3">54</item>
>> >> >> [t]<item id="i71"[t]sector="s1"[t]subsector="u3">2</item>
>> >> >> [t]<item id="i23"[t]sector="s2"[t]subsector="u1">345</item>
>> >> >> [t]<item id="i7"[t]sector="s2"[t]subsector="u1">67</item>
>> >> >> [t]<item id="i80"[t]sector="s1"[t]subsector="u3">7754</item>
>> >> >> [t]<item id="i9"[t]sector="s3"[t]subsector="u4">343</item>
>> >> >> [t]<item id="i4"[t]sector="s1"[t]subsector="u2">51</item>
>> >> >> [t]<item id="i99"[t]sector="s3"[t]subsector="u5">5637</item>
>> >> >> [t][t]
>> >> >> [t][t]<sector id="s1">Sector 1</sector>
>> >> >> [t]<sector id="s2">Sector 2</sector>
>> >> >> [t]<sector id="s3">Sector 3</sector>
>> >> >> >> >> >> [t]<subsector id="u1">Subsector 1</subsector>
>> >> >> [t]<subsector id="u2">Subsector 2</subsector>
>> >> >> [t]<subsector id="u3">Subsector 3</subsector>
>> >> >> [t]<subsector id="u4">Subsector 4</subsector>
>> >> >> [t]<subsector id="u5">Subsector 5</subsector>
>> >> >> </data>
>> > >> >> >> >> ---
>> GSM.By.COM - hmrepmer-l`c`ghm qnrnb{u reketnmnb qr`md`pr` GSM,
>> `jqeqqs`pnb h g`ow`qrei j mhl. Xhpnjhi b{anp, p`gslm{e vem{,
>> noep`rhbm` dnqr`bj`. Pelnmr reketnmnb. http://www.gsm.by.com
>


---
GSM.By.COM - hmrepmer-l`c`ghm qnrnb{u reketnmnb qr`md`pr` GSM,
`jqeqqs`pnb h g`ow`qrei j mhl. Xhpnjhi b{anp, p`gslm{e vem{,
noep`rhbm` dnqr`bj`. Pelnmr reketnmnb. http://www.gsm.by.com


---
GSM.By.COM - hmrepmer-l`c`ghm qnrnb{u reketnmnb qr`md`pr` GSM,
`jqeqqs`pnb h g`ow`qrei j mhl. Xhpnjhi b{anp, p`gslm{e vem{,
noep`rhbm` dnqr`bj`. Pelnmr reketnmnb. http://www.gsm.by.com


Current Thread