From: "Allen Jones" <jonesa(_at_)newschool(_dot_)edu>
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="{(_at_)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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--