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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:30:34+00:00 2026-06-08T17:30:34+00:00

New to XML/XSL/Xpath, and I’ve scoured these boards for an answer to a seemingly

  • 0

New to XML/XSL/Xpath, and I’ve scoured these boards for an answer to a seemingly simple problem, but maybe I’m too new to XSL to understand some of the answers out there that might address this.

I want to select a set of nodes that match a different set of node values stored elsewhere in the doc, so that:

<body>
    <partlist>
        <part>head</part>
        <part>spleen</part>
        <part>toe</part>
    </partlist>
    <parts>
        <head>this is a head</head>
        <spleen>this is a spleen</spleen>
        <toe>big toe</toe>
        <toe>big toe</toe>
    <parts>
</body>

So that, let’s say I want to count all the “parts”, but I don’t know the “parts” node names, I would want an XPath expr to match a set of nodes whose names are equal to the values of another set of nodes…

I am new enough to XSL to both imagine that a solution is very simple, but experienced enough to realize that expecting a simple solution from XSL is a sure wrong path.

In my procedural-based ignorance, this is what I have tried:

<xsl:template match="/">
    <xsl:apply-templates select="partlist/part">
        <xsl:with-param name="parts" select="parts"/>
    </xsl:apply-templates>
</xsl:template>
<xsl:template match="part">
    <xsl:param name="parts"/>
    <xsl:value-of select="count($parts[.])"/>        
</xsl:template>

But this is completely wrong. Any help is much appreciated.

Edit: Thanks for the answers, but I think I’m not being understood – the fault is mine, because I haven’t been perfectly clear… What I need is a single result telling me if there are ANY nodes that match the node value of the referring set… that I think changes the query, because I’m not trying to output a list of counts, I’m trying to match a set against a set to count the total… but let me clarify with XSL, if such a thing is possible.. here’s my code from above, slightly modified to make my intention clear:

<xsl:template match="/">
    <xsl:apply-templates select="partlist/part">
        <xsl:with-param name="parts" select="parts"/>
    </xsl:apply-templates>
</xsl:template>
<xsl:template match="part">
    <xsl:param name="parts"/>
    <xsl:if select="count($parts[.]) &gt; 0">1</xsl:if>        
</xsl:template>

the above when applied to the xml doc example should output:

1

Does this make sense?

Edit: I should also specify that I am limited to XSL 1.0

  • 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-08T17:30:36+00:00Added an answer on June 8, 2026 at 5:30 pm

    You can use the local-name() function to get the name of a node so you can compare it against a given value.

    For example, your stylesheet could be modified to this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:template match="/">
        <xsl:apply-templates select="body/partlist/part"/>
      </xsl:template>
    
      <xsl:template match="part">
        <xsl:variable name="part" select="."/>
        <xsl:value-of select="count(/body/parts/*[local-name() = $part])"/>
      </xsl:template>
    
    </xsl:stylesheet>
    

    Edited to add:

    You can also compare against sets of values instead of just single values. From XPath 1.0 spec, section 3.4:

    If one object to be compared is a node-set and the other is a string,
    then the comparison will be true if and only if there is a node in the
    node-set such that the result of performing the comparison on the
    string-value of the node and the other string is true.

    If you want to count how many elements you have under /body/parts whose local name matches the parts listed in /body/partlist/part, you could do it with this XPath expression:

    count(/body/parts/*[local-name() = /body/partlist/part])
    

    The last transformation from the question, added after the edit, could be rewritten for example like this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:template match="body">
        <xsl:apply-templates select="partlist">
          <xsl:with-param name="parts" select="parts"/>
        </xsl:apply-templates>
      </xsl:template>
    
      <xsl:template match="partlist">
        <xsl:param name="parts"/>
        <xsl:if test="count($parts/*[local-name() = current()/part]) &gt; 0">1</xsl:if>        
      </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very new to XSL (and XML for that matter), but I need to step
I'm new in xml, sorry for the dumb question. I'm trying to create xsl
This code:: xslProcessor = new XSLTProcessor(); xslProcessor.importStylesheet(xsl); result = xslProcessor.transformToFragment(xml, document); works fine in
I'm creating a new XML File out of a table. The problem is I
I'm new to XML validation using .xsd files. Maybe I'm not even asking the
I am very new to XSL and XPath. Apologies if this question shows some
I am new to XML and XSL. Im using IE9, both files are at
I am new to xml and xsl, if this is a easy question, and
Im completely new to XML/XSL/XSLT, and while i have been digging msdn, 3schools.com and
I have a problem with namespace position in result xml file after xsl transformation.

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.