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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:13:35+00:00 2026-05-25T23:13:35+00:00

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>

  • 0

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>   
                 <w:txbxContent>    
                     <w:p>             <!-- My Ignore case -->
                <w:r>
                       <w:t>paragraph1
                                </w:t>
                               </w:r>
                            </w:p>  
               </w:txbxContent>
                        </v:textbox>
                      </v:shape>
                   </w:pict>
                </w:r>   
                <w:r>
                  <w:t>Normal Paragraph1</w:t>
                </w:r>

              </w:p>

             <w:p>
                <w:r>
                   <w:t>paragraph2
                   </w:t>
                </w:r>
             </w:p>  
             <w:p>
                <w:r>
                   <w:t>paragraph3
                   </w:t>
                </w:r>
             </w:p>  

             <w:p>
                <w:r>
                   <w:t>paragraph4
                   </w:t>
                </w:r>
             </w:p>  
             <w:p>
                <w:r>
                   <w:t>paragraph5
                   </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><!-- Assume This is my Current Node -->
                </w:tc>   
                <w:tc>
                     <w:p><w:r><w:t>para8</w:t></w:r></w:p>
                </w:tc>
              </w:tr>
            </w:tbl>        
   </w:body>

</w:document>

Logic:1

So, now I want to count all preceding <w:p> nodes only within <w:body> tag. For example, now we have 5 nodes from <w:body>.

Logic:2

then if (<w:tbl> inside <w:body>) then count all <w:p> inside the <w:tbl> until the current node will reach.

So, the expected final is :7.

I have written query for this, but it is counting wrongly.

<xsl:value-of select="count($currentNode/preceding::w:p)"/>

It is written 8 because it will also count <w:p> inside <w:p>(see, my ignore case on my code). I don’t want it.

I need the total count like logic1+logic2.

  • 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-25T23:13:35+00:00Added an answer on May 25, 2026 at 11:13 pm

    It sounds like you want to ignore w:p elements that are nested within other w:p elements.

    If so, then you need to modify for statement to only include w:p element which have no w:p element as an ancestor.

    <xsl:value-of select="count($currentNode/preceding::w:p[not(ancestor::w:p)])"/>
    

    This should return a value of 7, instead of 8. I am assuming the current node is para8 here, by the way.

    So, assuming the following XML document

    <w:document xmlns:w="w">
       <w:body>
          <w:p>
             <w:r>
                <w:pict>
                   <v:shape xmlns:v="v">
                      <v:textbox>
                         <w:txbxContent>
                            <w:p><!-- My Ignore case -->
                               <w:r>
                                  <w:t>paragraph1 </w:t>
                               </w:r>
                            </w:p>
                         </w:txbxContent>
                      </v:textbox>
                   </v:shape>
                </w:pict>
             </w:r>
             <w:r>
                <w:t>Normal Paragraph1</w:t>
             </w:r>
          </w:p>
          <w:p>
             <w:r>
                <w:t>paragraph2 </w:t>
             </w:r>
          </w:p>
          <w:p>
             <w:r>
                <w:t>paragraph3 </w:t>
             </w:r>
          </w:p>
          <w:p>
             <w:r>
                <w:t>paragraph4 </w:t>
             </w:r>
          </w:p>
          <w:p>
             <w:r>
                <w:t>paragraph5 </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>
                <!-- Assume This is my Current Node -->
                <w:tc>
                   <w:p>
                      <w:r>
                         <w:t>para8</w:t>
                      </w:r>
                   </w:p>
                </w:tc>
             </w:tr>
          </w:tbl>
       </w:body>
    </w:document>
    

    If you use the following XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:w="w">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="/">
          <xsl:variable name="currentNode" select="//w:p[w:r/w:t = 'para8']" />
          Old: <xsl:value-of select="count($currentNode/preceding::w:p)"/> 
          -----
          New: <xsl:value-of select="count($currentNode/preceding::w:p[not(ancestor::w:p)])"/> 
       </xsl:template>
    
    </xsl:stylesheet>
    

    Then the following is returned:

      Old: 8 
      -----
      New: 7
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my xml Document. <w:document xmlns:w=w> <w:body> <w:p> <w:r> <w:t> Para1 </w:t> </w:r>
I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
I have an XML document that looks like this: <Data xmlns=http://www.domain.com/schema/data xmlns:dmd=http://www.domain.com/schema/data-metadata > <Something>...</Something>
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 XML file contained archived news stories for all of last year. I was
Here is my ultimate goal... to take this xml file.. <?xml version=1.0?> <Songs> <Song>
I am beginner in PHP. I am trying to parse this xml file. <relationship>
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
In this the catalog.xml file. I have two books who have the same inventory

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.