RE: [xsl] mod position() tests positive all of the time

Subject: RE: [xsl] mod position() tests positive all of the time
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 30 Dec 2006 22:21:04 -0000
You only have one thumbnail in each object, therefore the position of the
thumbnail within the object is always one.

Try

<xsl:for-each select="...../object[position() mod 5 = 1]/thumbnail"

and remember also that the thumbnails are not siblings of each other, but
cousins, so instead of

following-sibling::thumbnail[position() lt 5]

you want

../following-sibling::object[position() lt 5]/thumbnail 

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

> -----Original Message-----
> From: Allen Jones [mailto:jonesa@xxxxxxxxxxxxx] 
> Sent: 30 December 2006 19:12
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] mod position() tests positive all of the time
> 
> Thanks everyone for their input.  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:
> 
> <insightResponse>
>   <searchResponse>
>     <collectionResultSet>
>       <collectionName>Digital Media Collection</collectionName>
>       <collectionID>1</collectionID>
>       <institutionID>Parsons</institutionID>
>       <vcID>NA</vcID>
>       <object cid="1::Parsons::NA" objectID="4641" imageID="200761"
> type="media" >
>             <collectionName>Digital Media Collection</collectionName>
>             <collectionID>1</collectionID>
>            <institutionID>Parsons</institutionID>
>            <vcID>NA</vcID>
>            <collectionCopyrightStatement>These materials may 
> be covered by copyright.</collectionCopyrightStatement>
>                  <thumbnail URL="http://somelink";
> mappingType="standard" mappingName="DublinCore" >
>                        <label name="Creator" order="1" 
> >Duchamp, Marcel</label>
>                        <label name="Title" order="2" >3 
> Stoppages</label>
>                        <label name="Date Created" order="3"
> >1913-1914</label>
>                        <label name="Type" order="4"
> >assemblage</label>
>                 </thumbnail>
>       </object>
>          <object cid="1::Parsons::NA" objectID="4342" imageID="200747"
> type="media" >
>         <collectionName>Digital Media Collection</collectionName>
>         <collectionID>1</collectionID>
>         <institutionID>Parsons</institutionID>
>         <vcID>NA</vcID>
>         <collectionCopyrightStatement>These materials may be 
> covered by copyright.</collectionCopyrightStatement>
>           <thumbnail URL="http://somelink"; mappingType="standard"
> mappingName="DublinCore" >
>           <label name="Creator" order="1" >Duchamp, Marcel</label>
>           <label name="Title" order="2" >Bicycle Wheel</label>
>           <label name="Date Created" order="3" >1951</label>
>           <label name="Type" order="4" >assemblage</label>
>         </thumbnail>
> 
> ....
> </collectionResultSet>
> </searchResponse>
> </insightResponse>
> 
> 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 am using Chuck Knell's suggestion of a stylesheet, but I am 
> getting the same result.
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
>   <xsl:stylesheet version="1.0"
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>   <xsl:output method="html" encoding="iso-8859-1"/>
> 
> <xsl:template match="/">
>     <xsl:apply-templates />
>   </xsl:template>
> 
> <xsl:template match="insightResponse">
>     <xsl:apply-templates />
>   </xsl:template>
> 
> <xsl:template match="searchResponse">
>     <xsl:apply-templates />
>   </xsl:template>
> 
> <xsl:template match="collectionResultSet">
>     <xsl:apply-templates />
>   </xsl:template>
> 
> <xsl:template match="object">
>     <xsl:apply-templates />
>   </xsl:template>
> 
> <xsl:template match="thumbnail">
>     <xsl:choose>
>       <xsl:when test="position() mod 5 = 1">
>         <tr>
>           <td align="center">
>             <img src="{@URL}" />
>             <xsl:apply-templates />
>           </td>
>         </tr>
>       </xsl:when>
>       <xsl:otherwise>
>         <td align="center">
>           <img src="{@URL}" />
>           <xsl:apply-templates />
>         </td>
>       </xsl:otherwise>
>     <xsl:choose>
>   </xsl:template>
>   
> <xsl:template match="label">
>     <xsl:value-of select="." />
>   </xsl:template>
> </xsl:stylesheet>

Current Thread