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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:30:13+00:00 2026-05-11T12:30:13+00:00

I am trying to build a list that parses my entire xml document. I

  • 0

I am trying to build a list that parses my entire xml document. I need to list the numeric names then the alpha names. The list should look something like this.

6 6600 Training 6500 Training  A Accelerated Training  T Training 

This is a snippet of the xml.

<courses>     <course>                  <name>Accelerated Training</name>     </course>     <course>                 <name>6600 Training</name>     </course>             <course>                 <name>Training</name>     </course>     <course>                 <name>6500 Training</name>     </course>     </courses>    

This is the code I am currently using. I found this in another question on the site and have customized it somewhat. Currently it doesn’t take into account my need for parsing by number and it also returns out of alphabetical order.

<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>     <xsl:output omit-xml-declaration='yes' indent='yes'/>    <xsl:variable name='vLower' select= ''abcdefghijklmnopqrstuvwxyz''/>    <xsl:variable name='vUpper' select= ''ABCDEFGHIJKLMNOPQRSTUVWXYZ''/>     <xsl:key name='kTitleBy1stLetter' match='courses/course'  use='substring(name,1,1)'/>        <xsl:template match='/*'>            <xsl:for-each select='course [generate-id() = generate-id(key('kTitleBy1stLetter', substring(name,1,1)) [1] ) ]'>               <xsl:variable name='v1st' select='substring(name,1,1)'/>               <h2><xsl:value-of select='$v1st'/></h2>               <div class='{translate($v1st, $vUpper, $vLower)}-content'>         <ul>           <xsl:for-each select='key('kTitleBy1stLetter',$v1st)'>                            <li><xsl:value-of select='name'/></li>           </xsl:for-each>                   </ul>             </div>           </xsl:for-each>           </xsl:template> </xsl:stylesheet> 
  • 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. 2026-05-11T12:30:13+00:00Added an answer on May 11, 2026 at 12:30 pm

    Basically you need to group by first letter and sort by <name>. You are on a good way with your Muenchian grouping approach already.

    I would suggest an alternative that’s a bit easier on the eye:

    <xsl:key name='kInitial' match='course' use='substring(name, 1, 1)' />  <xsl:template match='courses'>   <xsl:apply-templates select='course' mode='initial'>     <xsl:sort select='name' />   </xsl:apply-templates> </xsl:template>  <xsl:template match='course' mode='initial'>   <xsl:variable name='initial' select='substring(name, 1, 1)' />   <xsl:variable name='courses' select='key('kInitial', $initial)' />   <xsl:if test='generate-id() = generate-id($courses[1])'>     <h2><xsl:value-of select='$initial'/></h2>     <ul>       <xsl:apply-templates select='$courses'>         <xsl:sort select='name' />       </xsl:apply-templates>     </ul>   </xsl:if> </xsl:template>  <xsl:template match='course'>   <li>     <xsl:value-of select='name'/>   </li> </xsl:template> 

    outputs:

    <h2>6</h2> <ul>   <li>6500 Training</li>   <li>6600 Training</li> </ul> <h2>A</h2> <ul>   <li>Accelerated Training</li> </ul> <h2>T</h2> <ul>   <li>Training</li> </ul> 

    EDIT: For the sake of legibility I left out the upper-casing of the first letter. The correct key would be this (you can’t use a variable in a key, hence the literal alphabet strings):

    <xsl:key name='kInitial' match='course' use='   translate(     substring(name, 1, 1),      'abcdefghijklmnopqrstuvwxyz',      'ABCDEFGHIJKLMNOPQRSTUVWXYZ'   ) ' /> 

    The same goes of course for the $initial variable in the second template, but here you can in fact use variables again.

    EDIT #2: Since sorting is case-sensitive as well, you can use the same expression:

    <xsl:sort select='translate(substring(name, 1, 1), $vLower, $vUpper)' /> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a list of strings that I need to pass
I'm trying to build a search engine that will check a list and then
I'm trying to build an AutoComplete DropDown List that will work on a Mobile
I am currently trying to build a little widget that will retrieve a list
I'm trying to get a target to build that has quite a long list
I am trying to build a list for my XML comments on my C#
I am trying to build a servlet that parses form input and creates a
I'm trying to build a list that contains all the objects from one list
I'm trying to build a list that will be used as the in clause
I'm trying to build a screen that will be a hierarchical list of bookmarks,

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.