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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:47:08+00:00 2026-05-26T01:47:08+00:00

This is my xml Document. <w:document xmlns:w=w> <w:body> <w:p> <w:r> <w:t> Para1 </w:t> </w:r>

  • 0

This is my xml Document.

<w:document xmlns:w="w">
 <w:body>
   <w:p>
        <w:r>
           <w:t>
               Para1
            </w:t>
        </w:r>
     </w:p>
   <w:p>
        <w:r>
           <w:t>
               Para2
            </w:t>
        </w:r>
     </w:p>
   <w:p>
        <w:r>
           <w:t>
               Para3
            </w:t>
        </w:r>
     </w:p>
   <w:p>
        <w:r>
           <w:t>
               Para4
            </w:t>
        </w:r>
     </w:p>
   <w:p>
        <w:r>
           <w:t>
               Para5
            </w:t>
        </w:r>
     </w:p>

   <w:tbl>
         <w:tr>
            <w:tc>
               <w:p>
                  <w:r>
                    <w:t>
                         Para6
                    </w:t>
                   </w:r>
                </w:p>
              </w:tc>
            <w:tc>
               <w:p>
                  <w:r>
                    <w:t>
                         Para7 
                    </w:t>
                   </w:r>
                </w:p>
              </w:tc>
           </w:tr>
        </w:tbl>
     <w:p>
        <w:r>
           <w:t>
               Para8
            </w:t>
        </w:r>
     </w:p>
  <w:tbl>
         <w:tr>
            <w:tc>
               <w:p>
                  <w:r>
                    <w:t>
                         Para9
                    </w:t>
                   </w:r>
                </w:p>
              </w:tc>
            <w:tc>
               <w:p>
                  <w:r>
                    <w:t>
                         Para10
                    </w:t>
                   </w:r>
                </w:p>
              </w:tc>
           </w:tr>
        </w:tbl>
    <w:p>
        <w:r>
           <w:t>
               Para11
            </w:t>
        </w:r>
     </w:p>
</w:body>
</w:document>

Now, I want to increment my global variable whenever <w:tbl><w:tr> encounters.for my above xml file,it has two <w:tr> nodes inside <w:tbl>.

So, for example :  
                1. if my current node is Para8 then it's count will be 1.
                2. if my current node is para11 then it's count will be 2.
   

How i do it?

  • 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-26T01:47:08+00:00Added an answer on May 26, 2026 at 1:47 am

    XSLT is a functional language and in any functional language the value of a variable, one set, cannot be updated. One needs a “paradigm shift” — to start thinking in a functional way — in order to understand that the “capability” to update variables isn’t necessary at all. For any imperative algorithm (that uses variable update) there is a corresponding functional algorithm (that doesn’t require update of any variable).

    There are a number of advantages using a functional programming style over an imperative one — the main being that a functional program is much better to read, understand, maintain and even prove correct. Due to variables being immutable, the optimizer of a compiler can perform much more aggressive optimizations and this results in more efficient, highly optimized compiled programs.

    In this particular case, it isn’t necessary to update a variable in order to get the required count:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:w="w">
     <xsl:output method="text"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:for-each select=
          "//w:t
             [contains(., 'Para8')
             or
              contains(., 'Para11')
             ]
         ">
           <xsl:number level="any" count="w:tbl/w:tr"/>
           <xsl:text>&#xA;</xsl:text>
         </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

     <w:document xmlns:w="w">
        <w:body>
            <w:p>
                <w:r>
                    <w:t>                Para1             </w:t>
                </w:r>
            </w:p>
            <w:p>
                <w:r>
                    <w:t>                Para2             </w:t>
                </w:r>
            </w:p>
            <w:p>
                <w:r>
                    <w:t>                Para3             </w:t>
                </w:r>
            </w:p>
            <w:p>
                <w:r>
                    <w:t>                Para4             </w:t>
                </w:r>
            </w:p>
            <w:p>
                <w:r>
                    <w:t>                Para5             </w:t>
                </w:r>
            </w:p>
            <w:tbl>
                <w:tr>
                    <w:tc>
                        <w:p>
                            <w:r>
                                <w:t>                          Para6                     </w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:p>
                            <w:r>
                                <w:t>                          Para7                      </w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                </w:tr>
            </w:tbl>
            <w:p>
                <w:r>
                    <w:t>                Para8             </w:t>
                </w:r>
            </w:p>
            <w:tbl>
                <w:tr>
                    <w:tc>
                        <w:p>
                            <w:r>
                                <w:t>                          Para9                     </w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                    <w:tc>
                        <w:p>
                            <w:r>
                                <w:t>                          Para10                     </w:t>
                            </w:r>
                        </w:p>
                    </w:tc>
                </w:tr>
            </w:tbl>
            <w:p>
                <w:r>
                    <w:t>                Para11             </w:t>
                </w:r>
            </w:p>
        </w:body>
    </w:document>
    

    the wanted, correct result is produced:

    1
    2
    

    In case this value should be contained in a variable — to be used later somewhere in its scope, one will simply define the variable as:

     <xsl:variable name="vMyCount">
       <xsl:number level="any" count="w:tbl/w:tr"/>
     </xsl:variable>
    

    And you can use this variable as in the transformation below:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:w="w">
     <xsl:output method="text"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:for-each select=
          "//w:t
             [contains(., 'Para5')
             or
              contains(., 'Para8')
             or
              contains(., 'Para11')
             ]
         ">
         <xsl:variable name="vMyCount">
           <xsl:number level="any" count="w:tbl/w:tr"/>
         </xsl:variable>
         <xsl:value-of select=
          "concat($vMyCount,
                  substring('0', 1 + boolean(string($vMyCount)))
                  )"/>
           <xsl:text>&#xA;</xsl:text>
         </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    producing the same correct result:

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

Sidebar

Related Questions

This is my XML file. <w:document xmlns:w=w> <w:body> <w:p> <w:r> <w:pict> <v:shape xmlns:v=v> <v:textbox>
Considering this xml document: DECLARE @X XML (DOCUMENT search.SearchParameters) = '<parameters xmlns=http://www.educations.com/Search/Parameters.xsd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <parameter
For example, In this document < ?xml version=1.0 ? > < SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ xmlns:SOAP-ENC=http://schemas.xmlsoap.org/soap/encoding/
This is XML Document. <?xml version=1.0 encoding=UTF-8 standalone=yes?> <w:document xmlns:w=http://schemas.openxmlformats.org/wordprocessingml/2006/main> <w:body> <w:p> <w:pPr> <w:pStyle
This is my XML Document. <?xml version=1.0 encoding=UTF-8 standalone=yes?> <w:document xmlns:w=http://schemas.openxmlformats.org/wordprocessingml/2006/main> <w:body> <w:p> <!--
This is my XML Document(Small Snippt). <?xml version=1.0 encoding=UTF-8 standalone=yes?> <w:document xmlns:w=http://schemas.openxmlformats.org/wordprocessingml/2006/main> <w:body> <w:p>
This is my XML document <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:v="urn:schemas-microsoft-com:vml"> <w:body> <w:p>
I have an XML document that looks like this: <kmsg xmlns=http://url1 xmlns:env=url1 xmlns:xsi=http://www.w3.org/2001/XMLSchemainstance xsi:schemaLocation=http://location
Consider this simple XML document. The serialized XML shown here is the result of
I use Django's render_to_response to return an XML document. This particular XML document is

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.