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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:41:58+00:00 2026-05-29T07:41:58+00:00

I have an HTML file and i want to convert to XML document only

  • 0

I have an HTML file and i want to convert to XML document only using XSLT..

I want:

  1. All the nodes to be retained.
  2. And all elements are sorted.
  3. And code should be in dynamically.
  4. i have an comma(,)between the elements so i need to handle that as delimiter like <dl>,</dl> as where it comes..(not only comma some speces also want to retained)

i have an huge file so i want an simple code to process all the html nodes.here i explained my codeing with the xslt
if u understand it plz help me..

My HTML file is..

<span id="2102" class="one_biblio">
<span id="2103" class="one_section-title"><b>Title</b></span>
<span id="2204" class="one_authors">
    <span id="2205" class="one_author">, <!--here the comma arraives-->

        <!-- here the id value misplaced -->
        <span id="2207" class="one_surname">Surname</span>,<!--here the comma arraives-->
        <span id="2206" class="one_given-name">GivenName</span>,<!--here the comma arraives-->
  </span>
</span>
<span id="2208" class="one_title">
    <span id="2209" class="one_maintitle">technology</span>
</span>

And i want the Output XML file as:
Here the attribute class value is used as element name.
And the elements to be sorted.
And the comma(,) should be come within the delimiter tag.

  <biblio id="2102" >
    <section-title id="2103" ><b>Title</b></section-title>
                <authors id="2204" >
                        <author id="2205" >
                            <dl>,</dl>  <!--here i want like this-->
                            <!-- correrct the id -->
                            <given-name id="2206" >GivenName </given-name><dl>,</dl><!--here i want like this-->
                            <surname id="2207" >Surname</surname><dl>,</dl><!--here i want like this-->
                        </author>
                    </authors>
                    <title id="2208" >
                        <maintitle id="2209" >technology</maintitle>
                    </title>             
          </biblio>

The XSLT i wrote is ..

 <xsl:template match="*[@class]">   
    <xsl:element name="{substring-after(@class, 'mps_')}">
        <xsl:copy-of select="@*[not(name()='class')]"/>
        <xsl:if test="not(current())">
        <xsl:apply-templates>    
                            <xsl:sort select="@id" data-type="number"/>   
        </xsl:apply-templates>   
        </xsl:if>
    </xsl:element>
</xsl:template> 

Help me.......
  • 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-29T07:41:59+00:00Added an answer on May 29, 2026 at 7:41 am

    This XSLT 1.0 transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext">
         <xsl:output omit-xml-declaration="yes" indent="yes"/>
         <xsl:strip-space elements="*"/>
    
         <xsl:variable name="vrtfPass1">
           <xsl:apply-templates select="/*"/>
         </xsl:variable>
    
         <xsl:template match="node()|@*">
             <xsl:copy>
               <xsl:apply-templates select="node()|@*"/>
             </xsl:copy>
         </xsl:template>
    
         <xsl:template match="node()|@*" mode="pass2">
             <xsl:copy>
               <xsl:apply-templates select="node()|@*"/>
             </xsl:copy>
         </xsl:template>
    
         <xsl:template match="/">
          <xsl:apply-templates mode="pass2"
               select="ext:node-set($vrtfPass1)/*"/>
         </xsl:template>
    
         <xsl:template match="*[@class]" mode="pass2">
          <xsl:element name="{substring-after(@class, 'one_')}">
           <xsl:copy-of select="@*[not(name()='class')]"/>
           <xsl:apply-templates>
             <xsl:sort select="@id" data-type="number"/>
           </xsl:apply-templates>
          </xsl:element>
         </xsl:template>
    
         <xsl:template match=
          "text()
            [../self::span[@class]
            or
             preceding-sibling::node()[1]
                                [self::span[@class]]
             ]
               [contains(., ',')]">
            <xsl:value-of select="substring-before(., ',')"/>
            <dl>,</dl>
            <xsl:value-of select="substring-after(., ',')"/>
          </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document (corrected to be made well-formed !!!):

    <span id="2102" class="one_biblio">
        <span id="2103" class="one_section-title">
            <b>Title</b>
        </span>
        <span id="2204" class="one_authors">
            <span id="2205" class="one_author">, 
                <span id="2207" class="one_surname">Surname</span>,
                <span id="2206" class="one_given-name">GivenName</span>,
            </span>
        </span>
        <span id="2208" class="one_title">
            <span id="2209" class="one_maintitle">technology</span>
        </span>
    </span>
    

    produces the wanted, correct result:

    <biblio id="2102">
       <span id="2103" class="one_section-title">
          <b>Title</b>
       </span>
       <span id="2204" class="one_authors">
          <span id="2205" class="one_author">
             <dl>,</dl> 
    
             <span id="2207" class="one_surname">Surname</span>
             <dl>,</dl>
    
             <span id="2206" class="one_given-name">GivenName</span>
             <dl>,</dl>
    
          </span>
       </span>
       <span id="2208" class="one_title">
          <span id="2209" class="one_maintitle">technology</span>
       </span>
    </biblio>
    

    Explanation: Two-pass transformation. The first pass fixes the comma, the second pass does the rest of the processing.

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

Sidebar

Related Questions

I have an HTML file and i want to convert to XML only using
I want to convert local html file on iPhone to PDF document. I have
I have html files/Directories, I want to convert them to .chm help file, under
I have opened an HTML file using file_get_contents('http://www.example.com/file.html') and want to parse the line
I have an HTML file and I want to use javascript to call a
I have a html file that I want to trim. I want to remove
I have a javascript file main.js and five html files 1.html,2.html,3.html,4.html,5.html I want to
i have a Button on a HTML page . i want to attach file
I have html-file. I have to replace all text between this: [%anytext%]. As I
I have an XML file generated using javax.sql.rowset.WebRowSet.writeXml which looks like: <metadata> This section

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.