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 423719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:12:29+00:00 2026-05-12T19:12:29+00:00

I have a list of elements that I want to split into individual lists

  • 0

I have a list of elements that I want to split into individual lists of 3. The end result would be something like this:

<ul>
    <li>element</li>
    <li>element</li>
</ul>
<ul>
    <li>element</li>
    <li>element</li>
</ul>
<ul>
    <li>element</li>
    <li>element</li>
</ul>

My XSLT is like this, but it doesn’t work, because I can’t insert </ul>, and I can’t insert a less than sign (<).

<ul>
    <xsl:for-each select="$myroot/item">
        <li></li>

        <xsl:if test="position() mod $maxItemsPerColumn = 0">
            <!-- I want to close my ul, and start a new one here, but it doesn't work! -->
        </xsl:if>
    </xsl:for-each>
</ul>

Any ideas? Thanks in advance!

  • 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-12T19:12:30+00:00Added an answer on May 12, 2026 at 7:12 pm

    You don’t need to do anything fancy like recursion. And good lord, don’t even contemplate using CDATA.

    You just have to think like XSLT and ask: “What input element do I want to transform into my output element?”

    Assuming that each ul is supposed to contain N items, you want to transform every Nth input item, starting with the first, into a ul:

    <xsl:variable name="n" select="number(4)"/>
    
    <xsl:template match="/">
      <output>
        <xsl:apply-templates select="/root/item[position() mod $n = 1]"/>
      </output>
    </xsl:template>
    

    Each of these item elements becomes a ul that contains the item and each of its N-1 following siblings:

    <xsl:template match="item">
      <ul>
        <xsl:for-each select=". | following-sibling::item[position() &lt; $n]">
          <li>
            <xsl:value-of select="."/>
          </li>
        </xsl:for-each>
      </ul>
    </xsl:template>
    

    Assuming an input document like this:

    <root>
      <item>1</item>
      <item>2</item>
      <item>3</item>
      <item>4</item>
      <item>5</item>
      <item>6</item>
      <item>7</item>
      <item>8</item>
      <item>9</item>
    </root>
    

    …you get this output, if $n is set to 4:

    <output>
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
      </ul>
      <ul>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
      </ul>
      <ul>
        <li>9</li>
      </ul>
    </output>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of lists that looks like this: x[[state]][[year]] . Each element
I have a list that contains many sub-lists of 3 elements each, like: my_list
I have a list and I want to split it into sub lists with
My problem is simple: I have a long list of elements that I want
We have two lists: a=['1','2','3','4'] b=['2','3','4','5'] How to get a list with elements that
I have a list of elements which I would like to make sortable and
So I have input of a list with elements like this: calendar year 2008
I have a list of objects (Move's in this case) that I want to
I have a list of strings that look like this: abc|key1|486997 def|key1|488979 ghi|key2|998788 gkl|key2|998778
I have a list of li elements that I need to allow drag/drop into

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.