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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:56:23+00:00 2026-06-15T01:56:23+00:00

I’m trying to get the unique values of a custom generated sequence of strings

  • 0

I’m trying to get the unique values of a custom generated sequence of strings in XSLT.
The problem at hand is rather unusual since I have to first split a string on ‘.’ and chop of the last bit, that’s working fine but getting the unique values using the XSLT 2.0 distinct-values is not.

Given some input

<TreeNumberList>
  <TreeNumber>A01.001.001</TreeNumber>  
  <TreeNumber>A01.001.002</TreeNumber>  
  <TreeNumber>A01.001.003</TreeNumber>
  <TreeNumber>A01.002.111</TreeNumber>
</TreeNumberList>

The desired output would be an iterable sequence of

A01.001, A01.002

So far I have the following function

<xsl:function name="func:strip-last">
    <xsl:param name="str"></xsl:param>
    <xsl:value-of select="substring($str, 1, string-length($str) - 1)"></xsl:value-of>
</xsl:function>

<xsl:function name="func:parent-of">
    <xsl:param name="nodes"></xsl:param>
    <xsl:variable name="output">
    <xsl:for-each select="$nodes">
        <xsl:variable name="parent">
            <xsl:for-each select="tokenize(., '\.')">
                <xsl:if test="position() != last()">
                    <xsl:value-of select="."></xsl:value-of>
                    <xsl:text>.</xsl:text>
                </xsl:if>
            </xsl:for-each>
        </xsl:variable>
        <tmp><xsl:value-of select="func:strip-last($parent))"></xsl:value-of></tmp>
    </xsl:for-each>    
    </xsl:variable>
    <xsl:sequence select="distinct-values($output/*)"></xsl:sequence>
</xsl:function>

But this does not return a set of distinct elements, rather a sequence of all the elements involved. The eventual code will be a bit more contrived since the TreeNumbers themselves will not be unique but a some name retrieved through a key lookup will be. (For those recognizing the mark-up, it’s part of the MeSH XML)

I’ve also tried to use a key-ed index or group-by for uniqueness but those did not play well with the document fragments.

  • 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-06-15T01:56:24+00:00Added an answer on June 15, 2026 at 1:56 am

    The following expression gives the set of distinct values as a sequence of strings:

    distinct-values(TreeNumber/replace(., '\..*$', ''))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I've tracked down a weird MySQL problem to the two different ways I was
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.