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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:30:44+00:00 2026-06-06T17:30:44+00:00

There is list <nodes> <node attr=’1’/> <node attr=’0’/> <node attr=’1’/> <node attr=’1’/> </nodes> i

  • 0

There is list

<nodes>
<node attr='1'/>
<node attr='0'/>
<node attr='1'/>
<node attr='1'/>
</nodes>

i need to apply-templates all nodes and count it:

<xsl:apply-templates select='nodes/node'>
<xsl:if test='@attr=1'>
<xsl:number/>
</xsl:if>
</xsl:apply-templates>

but a haz in result not 123, result is 134. How to fix it in xslt-1.0? There is another way to set numbers to it? position() not help, and

<xsl:apply-templates select='nodes/node[@attr=1]'>
<xsl:if test='@attr=1'>
<xsl:number/>
</xsl:if>
</xsl:apply-templates>

not help to =(((

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

    Firstly, you have an error in your XSLT

    <xsl:apply-templates select='nodes/node'> 
       <xsl:if test='@attr=1'> <xsl:number/>     
       </xsl:if>
    </xsl:apply-templates> 
    

    You can’t have an xsl:if within an xsl:apply-templates. You need a matching xsl:template and put the code in there…

    <xsl:apply-templates select="nodes/node" />
    
    <xsl:template match="node">
       <xsl:if test='@attr=1'>
          <xsl:number/>     
       </xsl:if>
    <xsl:template> 
    

    In fact, you could do away with the xsl:if here, and just have the test in the template match

    <xsl:template match="node[@attr=1]">
        <xsl:number/>     
    <xsl:template> 
    

    But to answer your question, you probably need to use the count attribute on the xsl:number element to count only the elements you want

    <xsl:number count="node[@attr=1]"/>
    

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="/">
          <xsl:apply-templates select="nodes/node"/>
       </xsl:template>
    
       <xsl:template match="node[@attr=1]">
          <xsl:number count="node[@attr=1]"/>
       </xsl:template>
    
       <xsl:template match="node"/>
    </xsl:stylesheet>
    

    When applied to you XML, the result is 123

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

Sidebar

Related Questions

Is there a feature which expands all descendant nodes of currently selected node at
help me please. There is a list of nodes. <list> <item>1</item> <item>2</item> <item>3</item> <item>4</item>
Is there any module which list the related nodes based on the title and
Is there a list of them with examples accessible to a person without extensive
Is there a list of reserved memory addresses out there - a list of
Is there a list of the differences between the various versions of Rails somewhere
Is there a list of COM error codes somewhere? Related: HRESULT: 0x80010105 (RPC_E_SERVERFAULT) question
Is there a list of standard marker interfaces in Java? I've read (in some
In my list there are some name of the input box, it follow the
Why is there no list-style infinite type error when I define something like this

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.