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

Re: mod position() tests positive all of the time

Subject: Re: mod position() tests positive all of the time
From: "Thomas Stone" <stonethomasjames@xxxxxxxxx>
Date: Sat, 30 Dec 2006 14:46:27 -0800
Re:  mod position() tests positive all of the time
> From: "Allen Jones" <jonesa@xxxxxxxxxxxxx>
>
> As per Abel's suggection, the input xml data I am using is included in
> the post:

   This definitely helps!

> For the transformation I am thinking, There will be only 1 thumbnail
> for each object.  Ideally, I would like to get:
>
> <table>
> <tr><td align="center"><img src="http://somelink">< br />labels<br
> /></td><td>repeat sequence 4 more times</td></tr>
> <tr>five more cells</tr></table>

   I see the source document structure as a "collectionResultSet" of
"object"s.  Each object has one "thumbnail" and each thumbnail has several
"label"s.  Your transformation references within the thumbnail "position() mod
5 = 1" then start a new row.  On the second, third, fourth, and fifth
successive thumbnail records, you would like to append the current row.  On
the sixth thumbnail, you would like to start a new row, and the seventh
through tenth thumbnails you would like appended to that row.

   This cannot work the way you set it up for two reasons:

1) You walk the tree on each node instead of calling out a set of nodes.  The
"position()" function will only increment if you "select " many thumbnails in
your "apply-templates".  For example, the <xsl:template
match="collectionResultSet"> apply-templates call could be shown as this.

<xsl:apply-templates select="object/thumbnail" />


   This will select all of the thumbnails you want to display.  In this way,
the position() will increment as you expect.  (P.S. If you have more than one
"collectionResultSet" tag under your "searchResponse", then each one will
select only its object/thumbnail entities and will start over at position()
1.)


2) You have the end of the row, </tr>, inside you first thumbnail.  The second
thumbnail will be unable to "insert" within that record unless you call the
"apply-templates" again before the </tr>, re-processing all the thumbnails for
the rest of the row.  For example, after the </td> but before the </tr> in
your first thumbnail, the following code could be used.

<xsl:apply-templates select="../../object/thumbnail" mode="rest_of_row">
  <xsl:with-param name="row_start" select="position()" />
</xsl:apply-templates>


   And a new template would be added.

<xsl:template match="thumbnail" mode="rest_of_row">
  <xsl:param name="row_start" />

  <xsl:choose>
    <xsl:when test="position() > $row_start and $row_start + 4 >=
position()">
      <td align="center">
        <img src="{@URL}" />
        Append Column
        <xsl:apply-templates />
      </td>
    </xsl:when>
  </xsl:choose>
</xsl:template>


   This uses template modes and parameter passing, and references more than
just the current XPath pointers.  Learning these tools will be worth it for
you in the long run.

--
___________________________________________________
Search for products and services at:
http://search.mail.com

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.