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 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

Related Questions

Given An XSLT stylesheet with a global variable: <xsl:variable name=lang select=/response/str[@name='lang']/> Question Where from
I am using an XSLT stylesheet to create an Excel document from an XML
I am trying to dynamically generate an XSLT document from an XSLT stylesheet. In
I created an XSLT stylesheet which looks for a node and deletes it. This
I need to have my XSLT stylesheet sort my XML file's child nodes, but
I'm using jQuery's .getJSON function to parse a set of search results from a
Why aren't more webpages written using XML with an XSLT stylesheet? For separating content
On another thread about using XSLT to list every node in an XML file,
I have this XSLT stylesheet, where I'm trying to find nodes that contain an
A while ago I asked this question: using xslt stylesheet to convert xhtml blank

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.