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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:12:36+00:00 2026-06-01T10:12:36+00:00

The structure of my style sheet is as following: <xsl:apply-templates select=pattern1|pattern2|pattern3/> … <xsl:template match=pattern1|pattern2|pattern3>

  • 0

The structure of my style sheet is as following:

    <xsl:apply-templates select="pattern1|pattern2|pattern3"/>
        ...
    <xsl:template match="pattern1|pattern2|pattern3">
        <xsl:variable name="counter"> 
            <xsl:number/>
        </xsl:variable>
        ...
    </xsl:template>

The counter variable is reset for each pattern. I want to get a counter for all the matches.
How can I achieve it?
Thanks!

XML source structure as follow:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <div class="entry">
        <div class="headword">
            ...
        </div>
        <div class="information-forms">
            test infomation block
        </div>
        <div class="definition">
            <div>text </div>
            <div>text </div>
                  ... ...
            <div>text </div>
        </div>
        <div class="example-sentences">
            <ol>
                <li>sentence here</li>
                <li>sentence here</li>
            ... ...
                <li>sentence here</li>
            </ol>
        </div>
        <div class="synonyms-reference">
            <div class="syn-para">
                Synonyms: ... ...
            </div>
            <div class="ant-para">
                Antonyms: ... ... 
            </div>
        <div class="...">
              ...
        </div>
        </div>
    </div>
    <div class="entry">
        ...
    </div>
    <div class="entry">
        ...
    </div>
    ... ... 
</root>

I want to get a counter of nodes of multiple patterns under each div[@class=”entry”] node.

So the counter should be reset when starting in a new div[@class=”entry”] node.
XPath of the patterns is

div[@class='information-forms']
|
div[@class='definition'].div
|
div[@class='example-sentences']/ol/li

I can figure out how to do it by parse it twice with xsl style sheet.( First time put all matching nodes in one node.) But It seems to me that it can be done in a single pass. I hope someone experienced in XSL/XSLT can help me. Thanks.

  • 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-01T10:12:39+00:00Added an answer on June 1, 2026 at 10:12 am

    Try the following. Explanation: call a specific template for the set of nodes to be processed, supplying the set as a parameter, then use position() within the template.

    <xsl:template match="div[@class='entry']">
        <div>
            <xsl:variable name="divs" select="
            div[@class='information-forms']
            |
            div[@class='definition']/div
            |
            div[@class='example-sentences']/ol/li
            "/>
            <xsl:call-template name="divs">
                <xsl:with-param name="divs" select="$divs"/>
            </xsl:call-template>
        </div>
    </xsl:template>
    
    
    
    <xsl:template name="divs">
        <xsl:param name="divs"/>
        <xsl:for-each select="$divs">
            <pos><xsl:value-of select="position()"/></pos>
        </xsl:for-each>
    </xsl:template>
    

    With the XML input you supplied, this gives as result

    <?xml version="1.0" encoding="UTF-8"?>
    <out>
        <div>
            <pos>1</pos>
            <pos>2</pos>
            <pos>3</pos>
            <pos>4</pos>
            <pos>5</pos>
            <pos>6</pos>
            <pos>7</pos>
        </div>
        <div/>
        <div/>
    </out>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The xml file is having the following structure <?xml version=1.0 encoding=utf-8?> <?xml-stylesheet type=text/xsl href=TestFile.xsl?>
Given an input file with the following structure: <resources> <text name=property.to.match> <en_US>The American translation</en_US>
I have looked at XSL xsl:template match="/" but the match pattern that triggered my
i 've the following folder structure src\BAT\templates\admin\base.html src\BAT\media\base.css src\BAT\media\admin-media\base.css settings.py MEDIA_ROOT = os.path.join( APP_DIR,
File structure is as follows: index.php settings/ |-manage_account.php templates/viriditio-v2/ |-index.tpl templates/virditio-v2/css |-style.css localhost/~braden/virditio/index.php shows
I have the following file structure (XML files 'index.xml' in nested folders): index.xml foo/index.xml
I've been always guiding myself with the following CSS structure: #nav { } #nav
I'm using Iirf v2.0 . I have the following directory structure: / /library /library/index.php
I cleaned up someone's style sheet for a Dreamweaver site, by editing the css
how do we include style sheets from a template file in smarty? ca we

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.