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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:23:27+00:00 2026-05-12T09:23:27+00:00

We have an application which has a heirarchical group structure. Some of the groups

  • 0

We have an application which has a heirarchical group structure. Some of the groups are passed in this format:

/Geography/NA/US/California

I would like to “unroll” this string so that I can get a node set like the following:

/Geography
/Geography/NA
/Geography/NA/US
/Geography/NA/US/California

I know I can use str:tokenize and get a nodeset like so: [Geography, NA, US, California] but I’m at a loss of how to assemble the parts back together incrementally.

I have most of the exslt functions available to use, but no XSLT 2.0 functions.

Any help appreciated!

  • 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-12T09:23:27+00:00Added an answer on May 12, 2026 at 9:23 am

    This is quite easy in plain XSLT 1.0, all you need is a recursive function like so:

    <xsl:template name="UnrollString">
      <xsl:param name="string" select="''" />
      <xsl:param name="head"   select="'/'" />
    
      <xsl:variable name="tail" select="
        concat(
          substring-after($string, $head), 
          '/'
        )
      " />
      <xsl:variable name="lead" select="
        concat(
          $head, 
          substring-before($tail, '/')
        )
      " />
    
      <xsl:if test="not($tail = '/')">
        <token>
          <xsl:value-of select="$lead" />
        </token>
    
        <xsl:call-template name="UnrollString">
          <xsl:with-param name="string" select="$string" />
          <xsl:with-param name="head"   select="concat($lead, '/')" />
        </xsl:call-template>
      </xsl:if>
    </xsl:template>
    

    Output for '/Geography/NA/US/California' is:

    <token>/Geography</token>
    <token>/Geography/NA</token>
    <token>/Geography/NA/US</token>
    <token>/Geography/NA/US/California</token>
    

    Note that:

    • The function expects the string to start with a delimiter (i.e. a slash), or the first word (‘Geography’) will be missing in the output.
    • A single trailing slash is ignored.
    • The delimiter cold easily be generalized and passed in as a parameter.
    • You could build a hierarchy easily by placing the recursive call into the <token> element instead of outside.
    • The output order can be reversed (longest to shortest) by placing the recursive call above the <token> element instead of below it.
    • You would need to use the node-set() extension function to convert the returned tokens into something that can be used further.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Flex application which has to be deployed in some server. The
I have application which has some networking code which runs asynchronously. I have attached
I have an application which has legacy Struts actions extending org.apache.struts.StrutsActions. I would like
I have an application which has some classes that handle some specific functions, have
I have an application which has to live as a service, I create an
I have an application which has a similar interface to Visual Studio, in that
I have an application which has a Projects table and a Users table. In
I have an AJAX application which has used CSS divs to create panels on
I have a Silverlight application which has on it a Canvas. On that Canvas,
I have an MVC application which has a set of fields for contact details

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.