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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:42:04+00:00 2026-05-26T12:42:04+00:00

I must copy a <script> node from xml to html, but I need to

  • 0

I must copy a <script> node from xml to html, but I need to replace dinamically some lines of it, and also add new ones. So I need to search-and-replace strings while the entire node is copying.

XML example:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
id="slot" width="320" height="245">

   <script type="application/javascript"><![CDATA[
      var a = 2;
      var b = "abc";
      var c = new Array(0,0,0);
      alert("Input!");
   ]]></script>

   <!-- here svg drawing tags -->

</svg>

HTML output example:

<html>
   <head>
      <title>Example!</title>

      <script type="application/javascript">
          var a = 2;                          <!---same as xml--->
          var b = "def";                      <!---modified--->
          var c = new Array(0,0,0);           <!---same as xml---> 
          alert("This is a new example!");    <!---modified---> 
          var new = "new var";                <!---new code--->             
      </script>
   </head> 
   <body>
   </body>
</html>

If it’s much easy, I can use XTLS 2.0.
How can I do?

  • 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-26T12:42:04+00:00Added an answer on May 26, 2026 at 12:42 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"
            xmlns:svg="http://www.w3.org/2000/svg"
            xmlns:my="my:my">
            <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
            <xsl:param name="pSrcEdits">
             <line num="2" act="del"/>
             <line num="4" act="rep"
                   newLine="var c = new Array(1,1,1);"/>
             <line num="5" act="ins"
                   newLine="/* Inserted comment */"/>
            </xsl:param>
    
     <xsl:template match="node()|@*">
             <xsl:copy>
               <xsl:apply-templates select="node()|@*"/>
             </xsl:copy>
     </xsl:template>
    
     <xsl:template match="svg:script/text()">
      <xsl:variable name="vLines" select="tokenize(., '&#xD;?&#xA;')"/>
    
      <xsl:sequence select="my:editLines($vLines, $pSrcEdits/*)"/>
     </xsl:template>
    
     <xsl:function name="my:editLines" as="xs:string*">
      <xsl:param name="pLines" as="xs:string*"/>
      <xsl:param name="pCommands" as="element()*"/>
    
      <xsl:for-each select="$pLines">
       <xsl:variable name="vLineNum" as="xs:integer"
        select="position()"/>
       <xsl:variable name="vCommand"
         select="$pCommands[number(@num) eq  $vLineNum]"/>
       <xsl:sequence select="my:editSingle(., $vCommand)"/>
      </xsl:for-each>
     </xsl:function>
    
     <xsl:function name="my:editSingle" as="xs:string?">
      <xsl:param name="pLine" as="xs:string"/>
      <xsl:param name="pCommand" as="element()?"/>
    
      <xsl:sequence select=
      "if(not($pCommand))
         then concat($pLine, '&#xA;')
         else
          if($pCommand/@act eq 'del')
             then ()
             else
              if($pCommand/@act eq 'rep')
                then concat($pCommand/@newLine, '&#xA;')
                else (: 'ins' :)
                  concat($pCommand/@newLine, '&#xA;', $pLine, '&#xA;')
      "/>
    
     </xsl:function>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    id="slot" width="320" height="245">
    
       <script type="application/javascript"><![CDATA[
          var a = 2;
          var b = "abc";
          var c = new Array(0,0,0);
          alert("Input!");
       ]]></script>
    
       <!-- here svg drawing tags -->
    
    </svg>
    

    produces the wanted result (all commands carried out and the script edited):

    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
         id="slot"
         width="320"
         height="245">
    
       <script type="application/javascript">
           var b = "abc";
     var c = new Array(1,1,1);
     /* Inserted comment */
          alert("Input!");
    
    </script>
    
       <!-- here svg drawing tags -->
    
    </svg>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a script which must copy some names into a multidimensional array,
There must be a generic way to transform some hierachical XML such as: <element1
I have a situation where I must copy one NSManagedObject from the main context
I need script to copy on cron basis a list of files. Files selected
I have a script that generate me some command that I must execute... Example:
for some reason my Firefox4+GreaseMonkey Script loads jQuery twice. I copy'n'pasted the following snippet,
I need to create an RPM package from an ANT script that runs on
I have records in table1, if the records exist, it must copy into table2.
Why must a copy constructor's parameter be passed by reference?
I must be getting daft, but I can't seem to find how to read

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.