[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Newbie question: Incrementing the position in the

Subject: Re: Newbie question: Incrementing the position in the tree midstream
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 12 Apr 2004 16:26:51 -0400
xsl jump to position
At 2004-04-12 13:41 -0600, Durston, Andrew (AGRE) wrote:
I have a set of XML outputs from a database which splits a table into individual cells -

test-plan/object/cell N
test-plan/object/cell N+1
test-plan/object/cell N+2
test-plan/object/cell N+3

I can search to find cell N. I'd like to be able to print cell N, cell N+1, cell N+2 ... all at once and then when XSL goes back
to searching (via a For) through the tree, it skips N+1, N+2 etc. (basically does a table row and then skips to the beginning of
the next row). Without entering another XML attribute into our DB to indicate beginning and end of rows... How do I increment
the position, moving from object/cell N to object/cell N+1 midstream?

By jumping periodically through the cells and then only looking at the immediately-surrounding area.


I hope the example below helps to give you an idea of what to do in your situation; I've generalized it for a period of "n" entries.

........................ Ken


T:\ftemp>type durston.xml <?xml version="1.0" encoding="iso-8859-1"?> <objects> <object> <cell>1</cell> <cell>2</cell> <cell>3</cell> <cell>4</cell> <cell>5</cell> <cell>6</cell> <cell>7</cell> <cell>8</cell> <cell>9</cell> <cell>10</cell> <cell>11</cell> <cell>12</cell> <cell>13</cell> <cell>14</cell> <cell>15</cell> <cell>16</cell> <cell>17</cell> <cell>18</cell> <cell>19</cell> <cell>20</cell> <cell>21</cell> <cell>22</cell> </object> </objects> T:\ftemp>type durston.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output indent="yes"/>

<xsl:variable name="n" select="4"/>

<xsl:template match="object">
  <xsl:for-each select="cell[position() mod $n = 1]">
    <group>
      <xsl:for-each select=". | following-sibling::cell[position()&lt;$n]">
        <xsl:copy-of select="."/>
      </xsl:for-each>
    </group>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>saxon durston.xml durston.xsl
<?xml version="1.0" encoding="utf-8"?>

<group>
   <cell>1</cell>
   <cell>2</cell>
   <cell>3</cell>
   <cell>4</cell>
</group>
<group>
   <cell>5</cell>
   <cell>6</cell>
   <cell>7</cell>
   <cell>8</cell>
</group>
<group>
   <cell>9</cell>
   <cell>10</cell>
   <cell>11</cell>
   <cell>12</cell>
</group>
<group>
   <cell>13</cell>
   <cell>14</cell>
   <cell>15</cell>
   <cell>16</cell>
</group>
<group>
   <cell>17</cell>
   <cell>18</cell>
   <cell>19</cell>
   <cell>20</cell>
</group>
<group>
   <cell>21</cell>
   <cell>22</cell>
</group>



--
Public courses: Spring 2004 world tour of hands-on XSL instruction
Each week:   Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO
Hong Kong May 17-21; Bremen Germany May 24-28; Helsinki June 14-18

World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.