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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:27:36+00:00 2026-06-06T16:27:36+00:00

I want to convert one xml format to another specified format by using xslt.

  • 0

I want to convert one xml format to another specified format by using xslt. This is my Xml File.I have to create some dynamic xml element by using some type of recursive call in xslt.

<?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:pPr>
        <w:r>
            <w:t>Text1-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
            <w:pStyle w:val="Heading1" /> 
        </w:pPr>
        <w:r>
            <w:t>Text2-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
        </w:pPr>
        <w:r>
            <w:t>Text3-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
        </w:pPr>
        <w:r>
            <w:t>Text4-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
            <w:pStyle w:val="Heading2" /> 
        </w:pPr>
        <w:r>
            <w:t>Text5-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
        </w:pPr>
        <w:r>
            <w:t>Text6-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
            <w:pStyle w:val="Heading3" /> 
        </w:pPr>
        <w:r>
            <w:t>Text7-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
        </w:pPr>
        <w:r>
            <w:t>Text8-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
            <w:pStyle w:val="Heading1" /> 
        </w:pPr>
        <w:r>
            <w:t>Text9-</w:t>
        </w:r>  
    </w:p>

    <w:p>
        <w:pPr>
        </w:pPr>
        <w:r>
            <w:t>Text10-</w:t>
        </w:r>  
    </w:p>


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

And my required output xml is :

<Document>
      <Paragraph>Text1-</Paragraph> 
      <Heading1>
         <Title>Text2-</Title>
         <Paragraph>Text3-</Paragraph> 
         <Paragraph>Text4-</Paragraph> 
         <Heading2>
            <Title>Text5-</Title>
            <Paragraph>Text6-</Paragraph> 
            <Heading3>
                <Title>Text7-</Title>
                <Paragraph>Text8-</Paragraph>  
            </Heading3>         
         </Heading2>
      <Heading1>
      <Heading1>
         <Title>Text9-</Title>
         <Paragraph>Text10-</Paragraph> 
       <Heading1>      
</Document>

Please Guide me a way to get out of this issue…

  • 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-06T16:27:38+00:00Added an answer on June 6, 2026 at 4:27 pm

    Here is a sample stylesheet:

    <xsl:stylesheet 
      version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xpath-default-namespace="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:mf="http://example.com/mf"
      exclude-result-prefixes="xs w mf">
    
    <xsl:output indent="yes"/>
    
    <xsl:function name="mf:group" as="element()*">
      <xsl:param name="paragraphs" as="element()*"/>
      <xsl:param name="level" as="xs:integer"/>
      <xsl:for-each-group select="$paragraphs" group-starting-with="p[pPr/pStyle/@w:val = concat('Heading', $level)]">
        <xsl:choose>
          <xsl:when test="self::p[pPr/pStyle/@w:val = concat('Heading', $level)]">
            <xsl:element name="Heading{$level}">
              <Title><xsl:value-of select="r/t"/></Title>
              <xsl:sequence select="mf:group(current-group() except ., $level + 1)"/>
            </xsl:element>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates select="current-group()"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each-group>
    </xsl:function>
    
    <xsl:template match="document">
      <Document>
        <xsl:sequence select="mf:group(body/p, 1)"/>
      </Document>
    </xsl:template>
    
    <xsl:template match="p">
      <Paragraph>
        <xsl:value-of select="r/t"/>
      </Paragraph>
    </xsl:template>
    
    </xsl:stylesheet>
    

    When applied with Saxon 9.4 on your sample input document I get the following result:

    <?xml version="1.0" encoding="UTF-8"?>
    <Document>
       <Paragraph>Text1-</Paragraph>
       <Heading1>
          <Title>Text2-</Title>
          <Paragraph>Text3-</Paragraph>
          <Paragraph>Text4-</Paragraph>
          <Heading2>
             <Title>Text5-</Title>
             <Paragraph>Text6-</Paragraph>
             <Heading3>
                <Title>Text7-</Title>
                <Paragraph>Text8-</Paragraph>
             </Heading3>
          </Heading2>
       </Heading1>
       <Heading1>
          <Title>Text9-</Title>
          <Paragraph>Text10-</Paragraph>
       </Heading1>
    </Document>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert one xml file into another xml file using xslt.here, i
I have an HTML file and i want to convert to XML only using
In an XSLT, I want to convert an XML document to another one. The
I want to convert one xml to another xml by using XSLT2.0.While doing so,
I'm trying convert xml from one format to other using the XslCompiledTransform in c#.
I have an XML file containing some scientific text that I want to display
I have an HTML file and i want to convert to XML document only
I have three lists that I want to convert into one list. When I
I have a directory full of JPEGs. I want to convert every one of
I want to convert this linear loop into a concurrent one: for(Item item :

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.