Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3274368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:01:47+00:00 2026-05-17T19:01:47+00:00

I found an elegant solution for that problem here: xsl for-each: add code block

  • 0

I found an elegant solution for that problem here: xsl for-each: add code block every n rows?

I’d like to understand the xslt code and I was wondering if you could help me to understand it by taking a look at the link provided above.

Basically there are 3 <xsl:template>. To me the first 2 ones are enough to achieve the purpose. However I tried with only 2 <xsl:template> and it doesn’t work. In short the third one is required. Here it is:

<xsl:template match="gallery[not(position() mod 6 = 1)]"/>

The second template has a mode while the last one has not.

I have no idea when the last one is executed. Could you please help me to figure out it?

Thanks for your help.

Regards,

Roland

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:01:48+00:00Added an answer on May 17, 2026 at 7:01 pm

    Here is the complete code you were asking about. I happen to be the author, so let me explain:

    <xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
     <xsl:output omit-xml-declaration="yes" indent="yes"/> 
     <xsl:strip-space elements="*"/> 
    

    The following template overrides the XSLT built-in template for element nodes.
    It matches every 6k+1th gallery element. It cretes a tr element and inside its body puts the results of processing this gallery element togeether with the next 5. The processing is done in a special mode (“proc”) to distinguish this from the default anonymous mode in which the XSLT built-in templates started and continue to operate.

     <xsl:template match="gallery[position() mod 6 = 1]"> 
      <tr> 
       <xsl:apply-templates mode="proc" 
            select=".|following-sibling::gallery[not(position() > 5)]" 
       /> 
      </tr> 
     </xsl:template> 
    

    The following template is invoked in mode “proc” to process every gallery element in a group of 6 that should be in the same row.

    <xsl:template match="gallery" mode="proc"> 
      <td> 
        <img src="{gallery-image-location}" alt="{gallery-image-alt}"/> 
      </td> 
     </xsl:template> 
    

    The following template overrides the default processing of the XSLT built-in templates for all gallery elements, whose position is not of the type 6k+1 (they are not starting a new 6-tuple). It says simply not to do anything with any such element, because these elements are already processed in “proc” mode.

     <xsl:template match="gallery[not(position() mod 6 = 1)]"/> 
    </xsl:stylesheet> 
    

    You need to acquaint yourself with XSLT’s processing model, default processing and built-in templates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I have since found and published an efficient and elegant solution that transforms
I'm having a problem understanding the shift/reduce confict for a grammar that I know
I've already found this question on SO (which is exactly the same problem I'm
I'd like to automatically update a database column with an aggregate of another column.
I'm modeling a force-based physics simulation where several particles are interacting with each other.
I've been trying to deal with some delimited text files that have non standard
I need to find an elegant way to do 2 kinds of MixIns. First:
I have perl, v5.6.1 built for MSWin32-x86-multi-thread Binary build 638 provided by ActiveState. I
I've been trying to implement a simple component-based game object architecture using Objective-C, much
This question is kind of related to Handle URI hacking gracefully in ASP.NET in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.