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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:57:20+00:00 2026-06-09T10:57:20+00:00

I have an XML(XHTML) file which I’m transforming into another XML file by using

  • 0

I have an XML(XHTML) file which I’m transforming into another XML file by using XSLT. I’m able to transform all the contents successfully but I need to include one Javascript in the output file which I’m unable to include. Can anyone please tell me that how can I include a javascript in the output file by using XSLT.

My Input file:

<?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-type" content="text/html;  charset=utf-8" />
    </head>  
    <body>
     <div class="TF" id="id8">
      <div class="iDev">
        <div class="q">
              T <input type="radio" name="o0" id="t0" onclick="getFeedback()"/> 
            </div>
      </div>
     </div>
    </body>
    </html>

Desired Output

<?xml version="1.0" encoding="utf-8"?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-type" content="text/html;  charset=utf-8" />
        </head>  
        <body>
         <div class="QT" id="id10">
         <script type="text/javascript">
         <!-- //<![CDATA[
            var numQuestions = 4;
            var rawScore = 0;
            var actualScore = 0;
           function getAnswer()
           {
          }
            function calulate()
           {
          }
          //]]> -->
         </script>
          <div class="iDev">
            <div class="q">
              T <input type="radio" name="o0" id="t0" onclick="getFeedback()"/> 
            </div>
          </div>
         </div>
        </body>
       </html>

XSLT Part:

<xsl:template match="xhtml:div[@id='id8']/@*">
  <xsl:attribute name="class">QT</xsl:attribute>
   <xsl:attribute name="id">id10</xsl:attribute>
   <script type="text/javascript">
   <![CDATA[
            var numQuestions = 4;
            var rawScore = 0;
            var actualScore = 0;
           function getAnswer()
           {
          }
            function calulate()
           {
          }
          ]]>
          </script>
</xsl:template>

I have created identity template and changed the values of attributes where-ever it was required according to the desired output but still I don’t know how can I include the javascript after <div class="TF" id="id8"> this tag. Thanks!

  • 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-09T10:57:22+00:00Added an answer on June 9, 2026 at 10:57 am

    Plese try following xsl:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
      <xsl:output method="xml" indent="yes"/>
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="div[@id='id8']">
        <xsl:element name="div">
          <xsl:attribute name="class">QT</xsl:attribute>
          <xsl:attribute name="id">id10</xsl:attribute>
        </xsl:element>
        <script type="text/javascript">
          <![CDATA[         
           var numQuestions = 4;             
           var rawScore = 0;             
           var actualScore = 0;            
           function getAnswer()            
           {           
           }             
           function calulate()            
           {           
           }           
           ]]>
        </script>
      </xsl:template>
    </xsl:stylesheet>   
    

    Edited

    Input xml file is this:

        <?xml version="1.0" encoding="utf-8"?>
    <html>
      <head>
        <meta http-equiv="Content-type" content="text/html;  charset=utf-8" />
      </head>
      <body>
        <div id="id8">
        </div>
          <div class="iDev">
            <div class="q">
              T <input type="radio" name="o0" id="t0" onclick="getFeedback()"/>
            </div>
          </div>
      </body>
    </html>  
    

    Output xml is this:

    <?xml version="1.0" encoding="utf-8"?>
    <html>
    <head>
    <meta http-equiv="Content-type" content="text/html;  charset=utf-8" />
    </head>
    <body>
    <div class="QT" id="id10" /><script type="text/javascript">
    
           var numQuestions = 4;             
           var rawScore = 0;             
           var actualScore = 0;            
           function getAnswer()            
           {           
           }             
           function calulate()            
           {           
           }           
    
        </script>
      <div class="iDev">
        <div class="q">
          T <input type="radio" name="o0" id="t0" onclick="getFeedback()" />
        </div>
      </div>
    </body>
    </html>  
    

    I hope this will help you…

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

Sidebar

Related Questions

I have to convert from one XML (XHTML) file to another using XSLT. The
I have to convert from one XML (XHTML) file to another using XSLT. The
we have XSLT to transform XML into HTML in XHTML 1.0 Strict in XSLT
I want to change from one XML (XHTML) file to another using XSLT. In
I have an xml file I wish to transform using an xsl-document, but I
I am using Saxon to transform an XML file to XHTML. I am calling
I have the following code which is loading an xml file to populate a
I have a UserControl which rather than putting tags into its ascx markup file,
I have the following html file: <html xmlns=http://www.w3.org/1999/xhtml xml:lang=en dir=ltr lang=en> <head> </head> <body>
I have a simply XSLT 1.0 stylesheet, that turns XML documents in XHTML. I

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.