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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:44:12+00:00 2026-05-16T10:44:12+00:00

In a xslt-stylesheet I’m using the methods exsl:node-set and set:distinct to access and filter

  • 0

In a xslt-stylesheet I’m using the methods exsl:node-set and set:distinct to access and filter unique nodes from a variable that contains a result tree fragment.
I can write the values of these nodes into my output file, example:

<xsl:variable name="myNodes">
  <xsl:call-template name="getNodes"/>
</xsl:variable>

<xsl:for-each select="set:distinct(exsl:node-set($myNodes)/key)">
  <xsl:value-of select="."/>
</xsl:for-each>

The values of the keys are written in the output, just as expected.
However, if I try to use the values in an XPath expression, it fails:

<xsl:for-each select="set:distinct(exsl:node-set($myNodes)/key)">
  <xsl:variable name="result" select="/tree//somenode[@key = current()]"/>
  <xsl:value-of select="$result"/>
</xsl:for-each>

Now, the output is empty, whereas I know that there is a “somenode” in my input-xml that should be selected by the XPath expression and it’s value is not empty.

Now my question is: Why does this happen?

I’m using Java 1.6, Xerces 2.7 and Xalan 2.7.

update:
as requested, some data for the example:
xml doc contains:

<tree>
  <somenode key="123"/>
  <num>123</num>
  <num>0815</num>
</tree>

the getNodes template:

<xsl:template name="getNodes">
  <xsl:for-each select="/tree/num">
    <xsl:element name="key">
      <xsl:value-of select="."/>
    </xsl:element>
  </xsl:for-each>
</xsl:template>
  • 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-16T10:44:13+00:00Added an answer on May 16, 2026 at 10:44 am

    Here is a transformation that does something close to what you want:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:set="http://exslt.org/sets"
     xmlns:exsl="http://exslt.org/common"
     >
     <xsl:output omit-xml-declaration="yes"/>
    
     <xsl:template match="/">
      <xsl:variable name="myNodes">
        <xsl:call-template name="getNodes"/>
      </xsl:variable>
    
    
      <xsl:variable name="vDoc" select="/"/>
    
      <xsl:for-each select="set:distinct(exsl:node-set($myNodes)/key)">
        <xsl:variable name="result" select="$vDoc/tree//somenode[@key = current()]"/>
        <xsl:copy-of select="$result"/>
      </xsl:for-each>
     </xsl:template>
    
     <xsl:template name="getNodes">
      <xsl:for-each select="/tree/num">
        <xsl:element name="key">
          <xsl:value-of select="."/>
        </xsl:element>
      </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <tree>
      <somenode key="123"/>
      <num>123</num>
      <num>0815</num>
    </tree>
    

    the wanted result is produced:

    <somenode key="123"/>
    

    Do note:

    1. The source XML document cannot direstly be accessed inside the <xsl:for-each>, because this instruction sets the current node to a node in another document — the temporary tree created by exsl:node-set().

    2. For this reason we capture the source XML document in a variable $vDoc. We access the source XML document inside the <xsl:for-each> via this variable.

    3. The element <somenode key="123"/> has no text-node descendents and hence no string value. Using <xsl:value-of> on it will not produce any output. This is why we use <xsl:copy-of> here — it copies the complete element and we see the result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 498k
  • Answers 498k
  • 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 What if you create a schema on the root Source,… May 16, 2026 at 12:11 pm
  • Editorial Team
    Editorial Team added an answer Remove the \[\] from around the $(getgitbranch). The characters output… May 16, 2026 at 12:11 pm
  • Editorial Team
    Editorial Team added an answer Have a look at the <database-object> mapping; it will allow… May 16, 2026 at 12:11 pm

Trending Tags

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

Top Members

Related Questions

I am using an XSLT stylesheet to create an Excel document from an XML
I'm using an XSLT stylesheet (by Antennahouse) to convert XHTML to an XSL-FO file.
I created an XSLT stylesheet which looks for a node and deletes it. This
I want to apply an XSLT Stylesheet to an XML Document using C# and
I have a set of xslt stylesheet files. I need to produce the fastest
I'm using an XSLT to transform from one XML standard to another. The particular
I have a xslt stylesheet with multiple xsl:import s and I want to merge
I'm applying an XSLT stylesheet to the following XML file: <top xmlns=http://www.foo.com/bar> <elementA />
I have an xslt stylesheet that needs to call a C# XSLT extension function
I want to attach an xslt stylesheet to an XML document that I build

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.