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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:31:33+00:00 2026-05-27T01:31:33+00:00

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>

  • 0

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> <!-- Assume Current Node -->
 </w:p>
 <w:p>
  <w:r>
     <w:t>Sample data</w:t>
  </w:r>

  <w:r>
    <w:pict>
       <v:group>
         <v:shape>
            <v:textbox>
              <w:txbxContent>
                 <w:p>
                    <w:r>
                        <w:t>Sample data1</w:t>
                    </w:r>
                  </w:p>
              </w:txbxContent>
            </v:textbox>
         </v:shape>
         <v:shape>
            <v:textbox>
              <w:txbxContent>
                 <w:p>
                    <w:r>
                        <w:t>Sample data2</w:t>
                    </w:r>
                  </w:p>
              </w:txbxContent>
            </v:textbox>
         </v:shape>
       </v:group>
    </w:pict>
  </w:r>
</w:p>
</w:body>
</w:document>

My required XML transformation result should look like this :

<Document>
   <paragraph>sample data</paragraph>
   <group>
        <paragraph>sample data1</paragraph>
        <paragraph>sample data1</paragraph>
    </group>
</Document>

My current XSLT snippet is

<Document>
<xsl:template match="//w:body/w:p">
<xsl:for-each select="following-sibling::*">
          <xsl:choose>
            <xsl:when test="self::w:p//v:group">

              <xsl:choose>
                <xsl:when test="self::w:p[not(ancestor::v:group)]">
              <xsl:apply-templates select="self::w:p"><!--this template take care about getting data inside w:p-->
              </xsl:apply-templates>
                </xsl:when>
              </xsl:choose>
              <group>
              <xsl:apply-templates select="descendant::w:p"> <!--this template take care about getting data inside w:p-->
                </xsl:apply-templates>
             </group>
            </xsl:when>
          </xsl:choose>
</xsl:for-each>
</xsl:template>
</Document>

But it produced output like this :

<Document>
 <paragraph>sample data</paragraph>
 <paragraph>sample data1</paragraph>
 <paragraph>sample data2</paragraph>
 <group>
   <paragraph>sample data1</paragraph>
   <paragraph>sample data2</paragraph>
 </group>
</Document>

How can I achieve the correct result that I mentioned above?

  • 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-27T01:31:33+00:00Added an answer on May 27, 2026 at 1:31 am

    Try following templates:

    <xsl:template match="/">
        <Document>
            <xsl:apply-templates select="node()"/>
        </Document>
    </xsl:template>
    
    <xsl:template match="//w:body/w:p/w:r">
            <xsl:apply-templates select="node()" />    
    </xsl:template>
    
    <xsl:template match="v:group">
        <group>
            <xsl:apply-templates select="..//w:t" />    
        </group>
    </xsl:template>
    
    <xsl:template match="w:t">
        <paragraph>
            <xsl:value-of select="."/>
        </paragraph>
    </xsl:template>
    

    it gives:

    <Document>
      <paragraph>Sample data</paragraph>
      <group>
        <paragraph>Sample data1</paragraph>
        <paragraph>Sample data2</paragraph>
      </group>
    </Document>
    

    Update: added new template <xsl:template match="//w:body/w:p/w:r"> to be independent from top level paragraph and group element order

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

Sidebar

Related Questions

I have the following XML document <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009' gd:etag='W/DEAERH47eCl7ImA9WhZTFEQ.'><id>http://code.google.com/feeds/issues/p/chromium/issues/full/921</id><published>2008-09-03T22:51:22.000Z</published><updated>2011-03-19T01:05:05.000Z</updated><title>Incorrect rendering</title><content
I have XML shaped like the following: <?xml version=1.0 encoding=UTF-8?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:openSearch=http://a9.com/-/spec/opensearch/1.1/ xmlns:docs=http://schemas.google.com/docs/2007
Having a XML document like this: <?xml version="1.0" encoding="UTF-8"?> <records type="array"> <record> <name>svn</name> <record-type>A</record-type>
I need some help. I have this xml document: <?xml version="1.0" encoding="utf-8"?> <MyItems> <Parent
I have this XML File: <?xml version="1.0" encoding="UTF-8"?> <karteikasten> <vokabel stufe="1"> <eng> <item>Hi</item> <item>Hello</item>
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>

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.