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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:33:37+00:00 2026-06-07T23:33:37+00:00

A Little update in my previous question already @Dimetre answered that Link Input XML

  • 0

A Little update in my previous question already @Dimetre answered that

Link

Input XML

<tutorial>
<lessons>
   <lesson>
     chapter Bat 20 
</lesson>
    <lesson>
        chapter Pen Ball 10~ 
    </lesson>
    <lesson>
        chapter Book 
    </lesson>
    <lesson>
        note lesson
    </lesson>
 <lessons1>
    <lesson>
        chapter Pencil 10
    </lesson>
    <lesson>
        description page
    </lesson>
    <lesson>
        chapter Car Tank 25
    </lesson>
</lessons1>
</lessons>

The Output will be

<Geography>


<historical>
  <social>
     <toc1>
        <toc>
           <chapter>chapter</chapter>
           <unit>Bat</unit>
           <pages>20</pages>
        </toc>
        <toc>
           <chapter>chapter</chapter>
           <unit>Pen Ball</unit>
           <pages>10</pages>
        </toc>
        <toc>
           <chapter>chapter</chapter>
           <unit>Book</unit>
           <pages>10</pages>
        </toc>
        <sample>
           <original>note lesson</original>
        </sample>
     </toc1>
     <toc2>
        <toc>
           <chapter>chapter</chapter>
           <unit>Pencil</unit>
           <pages>10</pages>
        </toc>
        <sample>
           <original>description page</original>
        </sample>
        <toc>
           <chapter>chapter</chapter>
           <unit>Car Tank</unit>
           <pages>25</pages>
        </toc>
     </toc2>
  </social>

Here in input XML I have for sample i have written two Lessons (lesson, Lesson1) actually but actually it my have n number of lessons. I think I am asking more but i am learning simultaneously.

Please help me & Guide me

Thanks in advance

Regards
Karthic

  • 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-07T23:33:39+00:00Added an answer on June 7, 2026 at 11:33 pm

    This transformation:

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
                <xsl:output omit-xml-declaration="yes" indent="yes"/>
                <xsl:strip-space elements="*"/>
    
             <xsl:template match="tutorial">
                <Geography>
                  <historical>
                    <social>
                         <xsl:apply-templates select=
                         "*[starts-with(name(),'lessons')]"/>
                    </social>
                  </historical>
                </Geography>
             </xsl:template>
    
             <xsl:template match="*[starts-with(name(), 'lessons')]">
              <xsl:variable name="vPos" select="position()"/>
    
              <xsl:element name="toc{$vPos}">
               <xsl:apply-templates/>
              </xsl:element>
    
             </xsl:template>
    
             <xsl:template match="lesson[starts-with(normalize-space(), 'chapter')]">
              <xsl:variable name="vNorm" select=
                             "translate(normalize-space(), '~', '')"/>
              <xsl:variable name="vAtUnit" select=
                             "substring-after($vNorm, 'chapter')"/>
    
              <xsl:variable name="vUnit" select=
              "replace($vAtUnit, '([^0123456789]+)(\d*)', '$1')"/>
    
              <xsl:variable name="vLastPart" as="xs:string" select=
               "substring-after($vAtUnit, $vUnit)"/>
    
              <xsl:variable name="vNum"
                select="concat($vLastPart, '10'[not($vLastPart)])"/>
    
              <toc>
                <chapter>chapter</chapter>
                <unit><xsl:value-of select="normalize-space($vUnit)"/></unit>
                <pages><xsl:value-of select="$vNum"/></pages>
              </toc>
             </xsl:template>
    
             <xsl:template match="lesson">
               <toc>
                   <sample>
                     <original><xsl:value-of select="normalize-space()"/></original>
                   </sample>
               </toc>
             </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document (corrected not to have lessons1 nested in lessons):

    <tutorial>
        <lessons>
           <lesson>
             chapter Bat 20
           </lesson>
           <lesson>
                chapter Pen Ball 10~
           </lesson>
           <lesson>
                chapter Book
           </lesson>
           <lesson>
                note lesson
           </lesson>
        </lessons>
        <lessons1>
            <lesson>
                chapter Pencil 10
            </lesson>
            <lesson>
                description page
            </lesson>
            <lesson>
                chapter Car Tank 25
            </lesson>
        </lessons1>
    </tutorial>
    

    produces the wanted, correct result:

    <Geography>
       <historical>
          <social>
             <toc1>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>Bat</unit>
                   <pages>20</pages>
                </toc>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>Pen Ball</unit>
                   <pages>10</pages>
                </toc>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>Book</unit>
                   <pages>10</pages>
                </toc>
                <toc>
                   <sample>
                      <original>note lesson</original>
                   </sample>
                </toc>
             </toc1>
             <toc2>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>Pencil</unit>
                   <pages>10</pages>
                </toc>
                <toc>
                   <sample>
                      <original>description page</original>
                   </sample>
                </toc>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>Car Tank</unit>
                   <pages>25</pages>
                </toc>
             </toc2>
          </social>
       </historical>
    </Geography>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the previous post. here is the link Previous Question Again Small Update in
UPDATE: QUESTION CLOSED: Fixed myself with a little backtracking. I'm using a framework that
Why only one overload throws this exception? Little update: I understand that there was
I little while back I posted this question . I have updated that question
A little update to the common question. As of the current version of Nodejs
Update: the much better answer has little to do with refactoring, but has to
UPDATE: To help clarify what I'm asking I have posted a little java code
UPDATE II: OK, I managed to narrow it down a little. I have a
This is an attempt to rephrase my previous question as a result of the
I'm refactoring a little bit of C# data access code from a previous developer

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.