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

The Archive Base Latest Questions

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

Below is the input XML (Little Big) sorry for the bigger input XML and

  • 0

Below is the input XML (Little Big) sorry for the bigger input XML and as well as output xml

<tutorial>
<lessons>
   <lesson>
     chapter unit 1 page
</lesson>
    <lesson>
        chapter unit 10~ page
    </lesson>
    <lesson>
        chapter unit page
    </lesson>
    <lesson>
        note lesson
    </lesson>
 <lessons1>
    <lesson>
        chapter unit 1 page
    </lesson>
    <lesson>
        description page
    </lesson>
    <lesson>
        chapter unit page
    </lesson>
</lessons1>
</lessons>
</tutorial>

Below is my Output Xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<Geography>


 <historical>
  <social>
     <toc1>
        <toc>
           <chapter>chapter</chapter>
           <unit>unit 1</unit>
           <pages>page</pages>
        </toc>
         <toc>
           <chapter>chapter</chapter>
           <unit>unit 10</unit>
           <pages>page</pages>
        </toc>
         <toc>
           <chapter>chapter</chapter>
           <unit>unit 10</unit>
           <pages>page</pages>
        </toc>
        <toc>
          <sample>
           <original>Note Lesson</orginal>
          </sample>
        </toc>
     </toc1>
     <toc2>
        <toc>
           <chapter>chapter</chapter>
           <unit>unit 1</unit>
           <pages>page</pages>
        </toc>
        <toc>
          <sample>
           <original>description page</orginal>
          </sample>
        </toc>
         <toc>
           <chapter>chapter</chapter>
           <unit>unit 10</unit>
           <pages>page</pages>
        </toc>
     </toc2>
  </social>

It’s quiet big output XML file sorry for that.

In unit if i have unit 1 in output it will displayed as unit 1 but for example if i have unit10~ it will displayed as unit 10 the ~ has to removed if there is no value in by default it has to displayed unit 10.

Little Brief Explanation

My Output XML has to differentiate in three categories

1) Chapter

2) unit

3) pages

The input will be in three different types of formats

1) The XML have Chapter,unit(number with tilda symbol) & pages

2) The XML have Chapter,unit(number without tilda symbol) & pages

3) The XML have only pages ex..(note & description) so here if for example i have 10~(unit) the output will show 10, if the input xml doesn’t have the value (for unit) in output xml it will show 10 as default number – karthic yesterday

Please help me and guide me with the help of XSLT.

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:54:16+00:00Added an answer on June 7, 2026 at 11:54 pm

    This transformation:

    <xsl:stylesheet version="2.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <xsl:output omit-xml-declaration="yes" indent="yes"/>
            <xsl:strip-space elements="*"/>
    
          <xsl:variable name="vNames" select="'chapter', 'unit', 'pages'"/>
    
         <xsl:template match="lessons">
            <Geography>
              <historical>
                <social>
                   <toc1>
                     <xsl:apply-templates select="lesson"/>
                   </toc1>
                   <xsl:apply-templates select="lessons1"/>
                </social>
              </historical>
            </Geography>
         </xsl:template>
    
         <xsl:template match="lesson[starts-with(normalize-space(), 'chapter')]">
          <xsl:variable name="vNorm" select=
                         "translate(normalize-space(), '~', '')"/>
          <xsl:variable name="vAtNumber" select=
                         "substring-after($vNorm, 'chapter unit')"/>
          <xsl:variable name="vNum" select=
           "if(matches($vAtNumber, '^\s*\d+'))
              then replace($vAtNumber, '(^\s*(\d+)).*$', '$2')
              else '10'
           "/>
          <xsl:analyze-string select="."
           regex="(chapter\s+)(unit\s*)(((\d*~?)\s+)?page)">
            <xsl:matching-substring>
              <toc>
                 <chapter>chapter</chapter>
                 <unit>unit <xsl:value-of select="$vNum"/></unit>
                 <pages>page</pages>
              </toc>
            </xsl:matching-substring>
          </xsl:analyze-string>
         </xsl:template>
    
         <xsl:template match="lesson">
           <sample>
             <original><xsl:value-of select="normalize-space()"/></original>
           </sample>
         </xsl:template>
    
         <xsl:template match="lessons1">
          <toc2>
           <xsl:apply-templates/>
          </toc2>
         </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <tutorial>
        <lessons>
           <lesson>
             chapter unit 1 page
        </lesson>
            <lesson>
                chapter unit 10~ page
            </lesson>
            <lesson>
                chapter unit page
            </lesson>
            <lesson>
                note lesson
            </lesson>
         <lessons1>
            <lesson>
                chapter unit 1 page
            </lesson>
            <lesson>
                description page
            </lesson>
            <lesson>
                chapter unit page
            </lesson>
        </lessons1>
        </lessons>
    </tutorial>
    

    produces the wanted, correct result:

    <Geography>
       <historical>
          <social>
             <toc1>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>unit 1</unit>
                   <pages>page</pages>
                </toc>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>unit 10</unit>
                   <pages>page</pages>
                </toc>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>unit 10</unit>
                   <pages>page</pages>
                </toc>
                <sample>
                   <original>note lesson</original>
                </sample>
             </toc1>
             <toc2>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>unit 1</unit>
                   <pages>page</pages>
                </toc>
                <sample>
                   <original>description page</original>
                </sample>
                <toc>
                   <chapter>chapter</chapter>
                   <unit>unit 10</unit>
                   <pages>page</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

Below is My input XML <First> <practice-session note=yes> <lessons>13000</lessons> <lessons>15000</lessons> <lessons>note</lessons> </practice-session> <practice-repeats note=yes>>
I am looking to transform a input xml given below <profile name=default> <color id=forecolor
below is the chunk of XML i get as input and i need to
I am looking to make an XSLT that will transform the input XML below:
Below are the XSLT <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:output omit-xml-declaration=yes/> <xsl:template match=/>
Given the contrived XML schema, sample XML input, and sample XSLT below used to
Below is my HTML <table width=100%> <tr><td><center><b>Browse your XML File below.</b></td></center> </tr> <tr><td><center><input type=file
Given below is my XML input. How do I copy or match selected elements
below is the input xml: <ns:TXLife xmlns:ns=http://ACORD.org/Standards/Life/2> <TXLifeResponse> <TransRefGUID/> <TransExeDate/> <TransExeTime/> <TransType tc=228/> </ns:TXLife>
I have a query in the xml and xslt The below is the Input

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.