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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:14:56+00:00 2026-05-15T11:14:56+00:00

xml: <mode>1</mode> <mode>2</mode> <mode>3</mode> <mode>4</mode> <mode>5</mode> <mode>6</mode> <mode>7</mode> <mode>8</mode> <mode>9</mode> <mode>10</mode> <mode>11</mode> <mode>12</mode> i

  • 0

xml:

<mode>1</mode>
<mode>2</mode>
<mode>3</mode>
<mode>4</mode>
<mode>5</mode>
<mode>6</mode>
<mode>7</mode>
<mode>8</mode>
<mode>9</mode>
<mode>10</mode>
<mode>11</mode>
<mode>12</mode>

i need to separate it on parts (for ex. on 4):

xslt:

<xsl:variable name="vNodes" select="mode"/>
<xsl:variable name="vNumParts" select="4"/>
<xsl:variable name="vNumCols" select="ceiling(count($vNodes) div $vNumParts)"/>
<xsl:for-each select="$vNodes[position() mod $vNumCols = 1]">
    <xsl:variable name="vCurPos" select="(position()-1)*$vNumCols +1"/>
    <ul>
        <xsl:for-each select="$vNodes[position() >= $vCurPos and not(position() > $vCurPos + $vNumCols -1)]">
            <li><xsl:value-of select="."/></li>
        </xsl:for-each>
    </ul>
</xsl:for-each>

this code is written by Dimitre Novatchev – great coder))

but for the number of nodes less then number of parts (for ex. i have 2 modes) this code does not work – it outputs nothing.

How it upgrade for that case (without choose construction)?

  • 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-15T11:14:56+00:00Added an answer on May 15, 2026 at 11:14 am

    Although the problem is incorrectly defined if the number of nodes is smaller than the number of parts, here is a transformation that I guess produces the output the OP most probably wants (Why didn’t he just specify this behavior???):

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="node()|@*">
       <xsl:copy>
         <xsl:apply-templates select="node()|@*"/>
       </xsl:copy>
     </xsl:template>
    
     <xsl:template match="/t">
      <t>
        <xsl:variable name="vNodes" select="mode"/>
        <xsl:variable name="vNumParts" select="4"/>
        <xsl:variable name="vNumCols" select="ceiling(count($vNodes) div $vNumParts)"/>
    
        <xsl:variable name="vrealNum">
          <xsl:choose>
            <xsl:when test="$vNumCols >1">
             <xsl:value-of select="$vNumCols"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="count($vNodes)"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:for-each select="$vNodes[position() mod $vrealNum = 1]">
            <xsl:variable name="vCurPos" select="(position()-1)*$vrealNum +1"/>
            <ul>
                <xsl:for-each select="$vNodes[position() >= $vCurPos and not(position() > $vCurPos + $vrealNum -1)]">
                    <li><xsl:value-of select="."/></li>
                </xsl:for-each>
            </ul>
        </xsl:for-each>
      </t>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the following XML document (he can’t even provide a well-formed XML document!):

    <t>
        <mode>1</mode>
        <mode>2</mode>
    </t>
    

    the output is what I guess the OP wanted…

    <t>
        <ul>
            <li>1</li>
            <li>2</li>
        </ul>
    </t>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 482k
  • Answers 482k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ubuntu's repositories usually contain up-to-date versions of Python modules (prefixed… May 16, 2026 at 6:55 am
  • Editorial Team
    Editorial Team added an answer If you're trying to use the custom HTML forms to… May 16, 2026 at 6:55 am
  • Editorial Team
    Editorial Team added an answer The instructions in the page you linked to recommend that… May 16, 2026 at 6:55 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.