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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:25:58+00:00 2026-06-07T20:25:58+00:00

With the previous post. here is the link Previous Question Again Small Update in

  • 0

With the previous post.

here is the link

Previous Question

Again Small Update in input xml the other validation are all same. Here only the chapter (element) is changing instead of chapter i will have numbers

<tutorial>
<lessons>
    <lesson>
     12000 Bat 20 
    </lesson>
    <lesson>
        15000 Pen Ball 10~ 
    </lesson>
    <lesson>
        14000 Book 
    </lesson>
    <lesson>
        note lesson
    </lesson>
</lessons>
<lessons1>
    <lesson>
        24000 Pencil 10
    </lesson>
    <lesson>
        description page
    </lesson>
    <lesson>
        8000 Car Tank 25
    </lesson>
</lessons1>

In the previous question we have Chapter was the first node (chapter Bat 20) but here I have 12000 bat 20

Desire output for the above input is

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

@Dimitre & @Tomalak From next time i will write fully prepared question and definitely i will post it with the solution what i have, now i am started learning little faster(XSLT) with this below output and previous output.

Please guide me here

Thanks in advance
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-07T20:26:01+00:00Added an answer on June 7, 2026 at 8:26 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[substring-before(normalize-space(), ' ')
                        castable as xs:integer
                        ]">
                  <xsl:variable name="vNorm" select=
                                 "translate(normalize-space(), '~', '')"/>
                  <xsl:variable name="vAtUnit" select=
                                 "substring-after($vNorm, ' ')"/>
    
                  <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>
                     <xsl:value-of select="substring-before($vNorm, ' ')"/>
                    </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:

        <tutorial>
        <lessons>
            <lesson>
             12000 Bat 20
            </lesson>
            <lesson>
                15000 Pen Ball 10~
            </lesson>
            <lesson>
                14000 Book
            </lesson>
            <lesson>
                note lesson
            </lesson>
        </lessons>
        <lessons1>
            <lesson>
                24000 Pencil 10
            </lesson>
            <lesson>
                description page
            </lesson>
            <lesson>
                8000 Car Tank 25
            </lesson>
        </lessons1>
    </tutorial>
    

    produces the wanted, correct result:

    <Geography>
       <historical>
          <social>
             <toc1>
                <toc>
                   <chapter>12000</chapter>
                   <unit>Bat</unit>
                   <pages>20</pages>
                </toc>
                <toc>
                   <chapter>15000</chapter>
                   <unit>Pen Ball</unit>
                   <pages>10</pages>
                </toc>
                <toc>
                   <chapter>14000</chapter>
                   <unit>Book</unit>
                   <pages>10</pages>
                </toc>
                <toc>
                   <sample>
                      <original>note lesson</original>
                   </sample>
                </toc>
             </toc1>
             <toc2>
                <toc>
                   <chapter>24000</chapter>
                   <unit>Pencil</unit>
                   <pages>10</pages>
                </toc>
                <toc>
                   <sample>
                      <original>description page</original>
                   </sample>
                </toc>
                <toc>
                   <chapter>8000</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

Here's a link to my previous question on this same block of code with
Following up on my previous post Link here , the other challenge we are
Please refer my previous post here . I did changes accordingly but getting error.
this is an extension to my previous post today which can be found here:
This post if a follow-up question to mt previous post: Android RESTful Web application
I inadvertently posted revisions to this previous post when I meant to update subsequent
This question is similar to my previous question but not the same ... please
Following on from a previous question, ( previous question here ), the problem I'm
First, here is the previous post that deals with the ListBox AccountListBox data binding
Following my previous post in this link I have another problem . Given the

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.