[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: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 02 Jan 2007 17:27:05 +0100
Re:  mod position() tests positive all of the time
Allen Jones wrote:
I'm still having the same counting
problem after working with some of the suggestions.  I have worked
mainly with Abel's and Chuck Knell's suggestion, and I'm getting the
same results.  This is output that comes from an XML gateway into a
PHP/Sablotron script for formatting.

As per Abel's suggection, the input xml data I am using is included in
the post:

Thanks for your input. That clarifies a lot. Others have already pointed out the difference between the siblings and cousins of object and thumbnail nodes. Here's a solution that works with your input, using only templates and no xsl:for-each (push model) or xsl:choose (often, an xsl:choose can be replaced by a template rule). It's largely a matter of taste which solution you want to use.


Because the thumbnail node lying inside the object node, the need for a separated mode has gone. Basically, the whole template becomes easier and more straightforward. I upgraded it to work with your input. A side effect of the chosen xpaths is that it also works with a structure that has more than one thumbnail inside an object node. I added some comments for clarification.

Consider placing "5" (your mod value) in a global variable. That will ease modification later on. Putting it in a parameter will make it configurable from the processor (if you can set parameters, that is).

HtH,

Cheers,
-- Abel Braaksma
  http://www.nuntia.nl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>


<!--
This one removes default template
output from other nodes that contain text.
Replace this with the rest of
your own templates
-->
<xsl:template match="/insightResponse/searchResponse
/collectionResultSet/*" priority="0"/>
<xsl:template match="collectionResultSet">
<html><body>
<table>
<!--
you probably want to add logic here for
collection name and institution etc.
-->
<xsl:apply-templates select="object" />
</table>
</body></html>
</xsl:template>
<!-- match each fifth object node -->
<xsl:template match="object[position() mod 5 = 1]">
<xsl:variable name="pos" select="position()" />
<tr>
<xsl:apply-templates
select="thumbnail |
(following-sibling::object/thumbnail)
[position() &lt; 5]"
/>
</tr>
</xsl:template>
<!-- create a thumbnail -->
<xsl:template match="thumbnail">
<td>
<img src="{@URL}" />
<xsl:apply-templates />
</td>
</xsl:template>
<!-- create label -->
<xsl:template match="label">
<br /><xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>


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-2007 All Rights Reserved.