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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:42:24+00:00 2026-05-27T17:42:24+00:00

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>

  • 0

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> <!-- Current Node -->
        <w:pPr>
            <w:pStyle w:val="Heading1"/>
        </w:pPr>

        <w:r>
            <w:t>
                 Paragraph1
            </w:t>
        </w:r>
    </w:p>

    <w:tbl>
        <w:t>table info
        </w:t>
    </w:tbl>

    <w:p>
        <w:pPr>
        </w:pPr>
        <w:r>
            <w:t>
                 Paragraph2
            </w:t>
        </w:r>
    </w:p>

    <w:p>
        <w:pPr>
        </w:pPr>
        <w:r>
            <w:t>
                 Paragraph3
            </w:t>
        </w:r>
    </w:p>

    <w:p>
        <w:pPr>
            <w:pStyle w:val="Heading1"/>
        </w:pPr>

        <w:r>
            <w:t>
                 Paragraph4
            </w:t>
        </w:r>
    </w:p>

    <w:p>
        <w:pPr>
        </w:pPr>
        <w:r>
            <w:t>
                 Paragraph5
            </w:t>
        </w:r>
    </w:p>

    <w:p>
        <w:pPr>
            <w:pStyle w:val="Heading1"/>
        </w:pPr>

        <w:r>
            <w:t>
                 Paragraph6
            </w:t>
        </w:r>
    </w:p>

</w:body>
</w:document>

Here, I want to select the following-sibling of the first<w:p> using for-each statement until it encounters the next<w:p> that having its <w:pPr><w:pStyle w:val="Heading1"/></w:pPr>.

for example,for first<w:p> i want to select only next three following-siblings.(ie,paragraph2,paragraph3 and including table info).because,4th <w:p> having <w:pPr><w:pStyle w:val="Heading1"/></w:pPr>.

The same case for 4th<w:p> if it is current node. Then i want to select only 5th <w:p>.

I dont know how to specify this condition in for-each.So, Can u guide me to get this…

My Required output is like:

<Document>
   <Heading1>
        <paragraph>paragrap1</paragraph>
        <paragraph>table info</paragraph>
        <paragraph>paragrap2</paragraph>
        <paragraph>paragrap3</paragraph>
   </Heading1>
   <Heading1>
        <paragraph>paragrap4</paragraph>
        <paragraph>paragrap5</paragraph>
   </Heading1>
   <Heading1>
        <paragraph>paragrap6</paragraph>
   </Heading1>
</Document>
  • 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-27T17:42:24+00:00Added an answer on May 27, 2026 at 5:42 pm

    Here, I want to select the following-sibling of the first <w:p>
    using for-each statement until it encounters the next <w:p> that
    having its <w:pPr><w:pStyle w:val="Heading1"/></w:pPr>.

    This XSLT 2.0 transformation shows one way of doing it using the XPAth 2.0 operator >>:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      exclude-result-prefixes="w xs">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="*/w:p[1]">
    
      <xsl:variable name="vNextWP" select=
      "following-sibling::w:p
        [w:pPr/w:pStyle/@w:val='Heading1']
         [1]
      "/>
    
      <xsl:copy-of select=
      "following-sibling::w:p[$vNextWP >> .]"/>
     </xsl:template>
    
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    
        <w:body>
    
            <w:p> <!-- Current Node -->
                <w:pPr>
                    <w:pStyle w:val="Heading1"/>
                </w:pPr>
    
                <w:r>
                    <w:t>
                         Paragraph1
                    </w:t>
                </w:r>
            </w:p>
    
            <w:p>
                <w:pPr>
                </w:pPr>
                <w:r>
                    <w:t>
                         Paragraph2
                    </w:t>
                </w:r>
            </w:p>
    
            <w:p>
                <w:pPr>
                </w:pPr>
                <w:r>
                    <w:t>
                         Paragraph3
                    </w:t>
                </w:r>
            </w:p>
    
            <w:p>
                <w:pPr>
                    <w:pStyle w:val="Heading1"/>
                </w:pPr>
    
                <w:r>
                    <w:t>
                         Paragraph4
                    </w:t>
                </w:r>
            </w:p>
    
            <w:p>
                <w:pPr>
                </w:pPr>
                <w:r>
                    <w:t>
                         Paragraph5
                    </w:t>
                </w:r>
            </w:p>
    
            <w:p>
                <w:pPr>
                    <w:pStyle w:val="Heading1"/>
                </w:pPr>
    
                <w:r>
                    <w:t>
                         Paragraph6
                    </w:t>
                </w:r>
            </w:p>
    
        </w:body>
    </w:document>
    

    exactly the wanted nodes are selected and copied to the output:

    <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
                <w:pPr>
                </w:pPr>
                <w:r>
                    <w:t>
                         Paragraph2
                    </w:t>
                </w:r>
            </w:p>
    <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
                <w:pPr>
                </w:pPr>
                <w:r>
                    <w:t>
                         Paragraph3
                    </w:t>
                </w:r>
            </w:p>
    

    Update: The OP has clarified what wanted the result of the transformation is (grouping), so here is:

    I. XSLT 1.0 solution:

     <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
     exclude-result-prefixes="w">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kFollowing"
      match="w:p[not(w:pPr/w:pStyle/@w:val = 'Heading1')]
            |
             w:tbl"
      use="generate-id(preceding-sibling::w:p
               [w:pPr/w:pStyle/@w:val = 'Heading1'][1])
      "/>
    
     <xsl:template match="/*">
      <Document>
       <xsl:apply-templates/>
      </Document>
     </xsl:template>
    
     <xsl:template match=
     "w:p[w:pPr/w:pStyle/@w:val = 'Heading1']">
    
      <Heading1>
       <xsl:apply-templates mode="inGroup" select=
        ". | key('kFollowing', generate-id())"/>
       </Heading1>
     </xsl:template>
    
     <xsl:template match="*" mode="inGroup">
      <paragraph>
        <xsl:value-of select="normalize-space(.//w:t)"/>
      </paragraph>
     </xsl:template>
    
     <xsl:template match="w:body/*" priority="-1"/>
    </xsl:stylesheet>
    

    when this transformation is applied on the newly provided XML document:

    <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    
    <w:body>
    
        <w:p> <!-- Current Node -->
            <w:pPr>
                <w:pStyle w:val="Heading1"/>
            </w:pPr>
    
            <w:r>
                <w:t>
                     Paragraph1
                </w:t>
            </w:r>
        </w:p>
    
        <w:tbl>
            <w:t>table info
            </w:t>
        </w:tbl>
    
        <w:p>
            <w:pPr>
            </w:pPr>
            <w:r>
                <w:t>
                     Paragraph2
                </w:t>
            </w:r>
        </w:p>
    
        <w:p>
            <w:pPr>
            </w:pPr>
            <w:r>
                <w:t>
                     Paragraph3
                </w:t>
            </w:r>
        </w:p>
    
        <w:p>
            <w:pPr>
                <w:pStyle w:val="Heading1"/>
            </w:pPr>
    
            <w:r>
                <w:t>
                     Paragraph4
                </w:t>
            </w:r>
        </w:p>
    
        <w:p>
            <w:pPr>
            </w:pPr>
            <w:r>
                <w:t>
                     Paragraph5
                </w:t>
            </w:r>
        </w:p>
    
        <w:p>
            <w:pPr>
                <w:pStyle w:val="Heading1"/>
            </w:pPr>
    
            <w:r>
                <w:t>
                     Paragraph6
                </w:t>
            </w:r>
        </w:p>
    
    </w:body>
    </w:document>
    

    the wanted, correct result is produced:

    <Document>
       <Heading1>
          <paragraph>Paragraph1</paragraph>
          <paragraph>table info</paragraph>
          <paragraph>Paragraph2</paragraph>
          <paragraph>Paragraph3</paragraph>
       </Heading1>
       <Heading1>
          <paragraph>Paragraph4</paragraph>
          <paragraph>Paragraph5</paragraph>
       </Heading1>
       <Heading1>
          <paragraph>Paragraph6</paragraph>
       </Heading1>
    </Document>
    

    II. XSLT 2.0 solution:

    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      exclude-result-prefixes="w"   >
        <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/*">
         <Document>
          <xsl:for-each-group
          select="*/*"
          group-starting-with="w:p[w:pPr/w:pStyle/@w:val = 'Heading1']">
           <Heading1>
             <xsl:for-each select="current-group()//w:t">
               <paragraph>
                 <xsl:sequence select="normalize-space(.)"/>
               </paragraph>
             </xsl:for-each>
           </Heading1>
          </xsl:for-each-group>
         </Document>
     </xsl:template>
    </xsl:stylesheet>
    

    when this XSLT 2.0 transformation is applied on the same XML document (above), the same wanted, correct result is produced:

    <Document>
       <Heading1>
          <paragraph>Paragraph1</paragraph>
          <paragraph>table info</paragraph>
          <paragraph>Paragraph2</paragraph>
          <paragraph>Paragraph3</paragraph>
       </Heading1>
       <Heading1>
          <paragraph>Paragraph4</paragraph>
          <paragraph>Paragraph5</paragraph>
       </Heading1>
       <Heading1>
          <paragraph>Paragraph6</paragraph>
       </Heading1>
    </Document>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
Given an XML document like this: <!DOCTYPE doc SYSTEM 'http://www.blabla.com/mydoc.dtd'> <author>john</author> <doc> <title>&title;</title> </doc>
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
Hi I have an xml document like this <root> <cert id=1> </cert> <cert id=2>
I have a xml document like this : <Node1 attrib1=abc> <node1_1> <node1_1_1 attrib2 =
Say I have a xml document that looks like this <foo> <bar id=9 />
I have an XML document looking similar to this: <items> <item cat=1 owner=14>bla</item> <item
I have this kind of node in my xml document: <parent ...> <a .../>
I have got an XML document which looks something like this. <Root> <Info>....</Info> <Info>....</Info>

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.