Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Abel Braaksma <abel.online@--------->
To:
Date: 1/2/2007 4:29:00 PM
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>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent