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

  • Home
  • SEARCH
  • 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 1868116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:38:42+00:00 2026-05-17T06:38:42+00:00

I am trying to transform a bit of xml which represents an image gallery

  • 0

I am trying to transform a bit of xml which represents an image gallery into an html table. (it must be done with html and not with css). How do I add the row break </tr><tr> every six or so columns with xsl?

I have this:

<xsl:for-each select="//email/gallery" >
<td>
    <img>
    <xsl:attribute name="src">
        <xsl:value-of select="gallery-image-location"/>
    </xsl:attribute>
    <xsl:attribute name="alt">
        <xsl:value-of select="gallery-image-alt"/>
    </xsl:attribute>
    </img>
</td>
<xsl:if test="????">
    </tr>
    <tr>
</xsl:if>
<xsl:for-each>

In Javascript I would do something like:

for (i=0; i<gallery.length; i++) {
    htm += '<td><img src="' +
    gallery[i].gallery-image-location +
    '" alt="'+ gallery[i].gallery-image-alt +'"></td>';

    if (i%6 == 5 && i != gallery.length-1) {
        htm += '</tr><tr>';
    }
}
  • 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-17T06:38:42+00:00Added an answer on May 17, 2026 at 6:38 am

    How do I add the row break
    every six or so columns with xsl?

    In XSLT you don’t!

    XSLT processes nodes, not tags.

    Here is the XSLT way of positional grouping:

    <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="*"/>
    
     <xsl:template match="gallery[position() mod 6 = 1]">
      <tr>
       <xsl:apply-templates mode="proc"
            select=".|following-sibling::gallery[not(position() > 5)]"
       />
      </tr>
     </xsl:template>
    
     <xsl:template match="gallery" mode="proc">
      <td>
        <img src="{gallery-image-location}" alt="{gallery-image-alt}"/>
      </td>
     </xsl:template>
    
     <xsl:template match="gallery[not(position() mod 6 = 1)]"/>
    </xsl:stylesheet>
    

    when this transformation is applied on the following XML document:

    <email>
        <gallery>
            <gallery-image-location>http://server/picts/1</gallery-image-location>
            <gallery-image-alt>Description 1</gallery-image-alt>
        </gallery>
        <gallery>
            <gallery-image-location>http://server/picts/2</gallery-image-location>
            <gallery-image-alt>Description 2</gallery-image-alt>
        </gallery>
        <gallery>
            <gallery-image-location>http://server/picts/3</gallery-image-location>
            <gallery-image-alt>Description 3</gallery-image-alt>
        </gallery>
        <gallery>
            <gallery-image-location>http://server/picts/41</gallery-image-location>
            <gallery-image-alt>Description 4</gallery-image-alt>
        </gallery>
        <gallery>
            <gallery-image-location>http://server/picts/5</gallery-image-location>
            <gallery-image-alt>Description 5</gallery-image-alt>
        </gallery>
        <gallery>
            <gallery-image-location>http://server/picts/6</gallery-image-location>
            <gallery-image-alt>Description 6</gallery-image-alt>
        </gallery>
        <gallery>
            <gallery-image-location>http://server/picts/7</gallery-image-location>
            <gallery-image-alt>Description 7</gallery-image-alt>
        </gallery>
        <gallery>
            <gallery-image-location>http://server/picts/8</gallery-image-location>
            <gallery-image-alt>Description 8</gallery-image-alt>
        </gallery>
        <gallery>
            <gallery-image-location>http://server/picts/9</gallery-image-location>
            <gallery-image-alt>Description 9</gallery-image-alt>
        </gallery>
    </email>
    

    the wanted, correct result is produced:

    <tr>
        <td>
            <img src="http://server/picts/1" alt="Description 1"/>
        </td>
        <td>
            <img src="http://server/picts/2" alt="Description 2"/>
        </td>
        <td>
            <img src="http://server/picts/3" alt="Description 3"/>
        </td>
        <td>
            <img src="http://server/picts/41" alt="Description 4"/>
        </td>
        <td>
            <img src="http://server/picts/5" alt="Description 5"/>
        </td>
        <td>
            <img src="http://server/picts/6" alt="Description 6"/>
        </td>
    </tr>
    <tr>
        <td>
            <img src="http://server/picts/7" alt="Description 7"/>
        </td>
        <td>
            <img src="http://server/picts/8" alt="Description 8"/>
        </td>
        <td>
            <img src="http://server/picts/9" alt="Description 9"/>
        </td>
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to transform each element of a numpy array into an array itself
I'm trying to decrypt an encrypted XML file and put it into a stream
I'm trying to implement an image zoom effect, a bit like how the zoom
I'm trying to transform the content of a CHM (Microsoft HTML Help) file's index
I've been trying to transform my XML documents to PDF through Apache FOP, but
Trying to understand an fft (Fast Fourier Transform) routine I'm using (stealing)(recycling) Input is
I'm trying to apply a transform to a 3D object in a STL File
I'm trying to write a query that extracts and transforms data from a table
Trying to get my css / C# functions to look like this: body {
I'm trying to create an application that converts a file from the HTML format

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.