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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:37:57+00:00 2026-05-26T10:37:57+00:00

I want to to select all the nodes for a given id but that

  • 0

I want to to select all the nodes for a given id but that could end in an additional number. How can I do that?

Example:

 <group id="list">
 <group id="list1">
 <group id="list2">
 <group id="map">
 <group id="map1">

The declaration Im having now:

<xsl:variable name="rule">
<data>
    <node>list</node>
    <node>map</node>
</data>
</xsl:variable>

<xsl:template match="/">
    <xsl:apply-templates select=".//group[ @id = exslt:node-set($rule)/data/node]"/>
</xsl:template>

and it only allows my to work on the nodes specified in the “rule” list. [XSLT v1.0]

Please advise.

  • 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-26T10:37:58+00:00Added an answer on May 26, 2026 at 10:37 am

    I. XSLT 1.0 solution:

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:param name="pIds">
      <id>list</id>
      <id>map</id>
     </xsl:param>
    
     <xsl:variable name="vIds" select=
      "document('')/*/xsl:param[@name='pIds']/*"/>
    
     <xsl:template match="group">
      <xsl:if test=
      "$vIds[. = current()/@id
            or
             starts-with(current()/@id, .)
            and
             substring-after(current()/@id, .)
            =
             floor(substring-after(current()/@id, .))
            ]
      ">
       <!-- Processing here: -->
       <xsl:copy-of select="."/>
      </xsl:if>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document:

    <t>
     <group id="list"/>
     <group id="list1"/>
     <group id="listX"/>
     <group id="list2"/>
     <group id="map"/>
     <group id="map123Z"/>
     <group id="map1"/>
    </t>
    

    processes (in this example copies) exactly the matching nodes:

    <group id="list"/>
    <group id="list1"/>
    <group id="list2"/>
    <group id="map"/>
    <group id="map1"/>
    

    Explanation:

    1. Use of the standard XPath functions starts-with(), substring-after() and floor().

    2. An easy test if a string is castable to an integer is: floor($s) = $s

    II. XSLT 2.0 solution:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:param name="pIds" select="'list', 'map'"/>
    
     <xsl:variable name="vIds" select=
      "document('')/*/xsl:param[@name='pIds']/*"/>
    
     <xsl:template match=
     "group
       [@id = $pIds
       or
        $pIds
          [starts-with(current()/@id, .)
         and
            substring-after(current()/@id, .)
           castable as
            xs:integer
           ]
        ]
     ">
       <!-- Processing here: -->
       <xsl:copy-of select="."/>
     </xsl:template>
    </xsl:stylesheet>
    

    Explanation: This solution is quite similar to the XSLT 1.0 solution with the following major differences:

    1. In XSLT 2.0 it is allowed to have variable/parameter references in the match pattern. Using this we avoid the <xsl:if> inside the template body.

    2. We define the parameter to contain a sequence of the desired strings.

    3. We use the standard XPath 2.0 operator castable as.

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

Sidebar

Related Questions

I want to select all nodes <cci:p> that do not have an attribute. So,
I've created a view that selects all nodes of type shoot. But I want
I can easily select all nodes with a given name in a namespace: $(namespace\\:nodename)
I want to select all elements that have an accesskey defined on them. I
I want to select all internal links, which are in my document, but not
I'm creating the MaskedTextBox in WP7.1 In that i want to select all text
This is probably pretty simple. I want to select all elements of a given
Simplified Question: What's the XPath to select all XML nodes with an attribute that
HI, I want to select all nodes other than first node.My xsl and xml
how can select all nodes with class myClass whose parent nodes don't have class

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.