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

I want to apply an XSLT Stylesheet to an XML Document using C# and
I have a xslt stylesheet with multiple xsl:import s and I want to merge
I want to attach an xslt stylesheet to an XML document that I build
I have a Java servlet which generates XML, translates it with an XSLT stylesheet,
The use of XSLT (XML Stylesheet Language Transform) has never seen the same popularity
Question Using XSLT 1.0, given a string with arbitrary characters how can I get
An XSLT-newbie problem: I need to substitute a text value in XML-file. All other
.NET XSLT engine allows passing objects to the XSLT processing engine through the AddExtensionObject
I have an xslt sheet with some text similar to below: <xsl:text>I am some
Does anyone have an XSLT that will take the app.config and render it into

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.