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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:45:51+00:00 2026-05-31T02:45:51+00:00

I have a javascript file that looks like this: if (x > 0 &&

  • 0

I have a javascript file that looks like this:

if (x > 0 && x < 100) {
    $('#thing').append('<foo id="foo' + x + '">' + stuff + '</foo>');
}

And an xsl stylesheet that looks like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="foo">
        <div>
            <xsl:copy-of select="@*"/>
            <xsl:value-of select="."/>
        </div>
     </xsl:template>
</xsl:stylesheet>

I want to be able to apply that template and possibly other ones to the xml contained in the javascript file.

In this case, the output should look like this:

if (x > 0 && x < 100) {
    $('#thing').append('<div id="foo' + x + '">' + stuff + '</div>');
}

I will use the following constraints on the javascript file if it makes it easier to parse:

  1. I will never use &, <, or > inside or between the XML tags.
  2. I will never use nested XML tags.
  3. I will only use double quotes (“) in or around the XML tags to set the element attributes.
  4. I will always have one or more spaces surrounding each < or > character in the regular javascript parts of the text.

I might be able to make other constraints as necessary.

I am using Saxon, so I can use XSLT 2.0 functions and saxon extensions.

  • 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-31T02:45:53+00:00Added an answer on May 31, 2026 at 2:45 am

    This seems to work (your input text in jsxml.txt):

    $ saxon9 -it main jsxml.xsl
    if (x > 0 && x < 100) {
        $('#thing').append('<div id="foo' + x + '">' + stuff + '</div>');
    }
    
    
    <xsl:stylesheet version="2.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:dpc="data:,dpc">
    
    <xsl:import href="http://web-xslt.googlecode.com/svn/trunk/htmlparse/htmlparse.xsl"/>
    
    <xsl:output method="text"/>
    
    <xsl:template name="main">
     <xsl:variable name="in" select="unparsed-text('jsxml.txt')"/>
      <xsl:copy-of select="dpc:serialise(dpc:apply-templates(dpc:htmlparse($in,'',false())))"/>
     </xsl:template>
    
    
    <xsl:function name="dpc:apply-templates">
     <xsl:param name="n"/>
     <xsl:apply-templates select="$n"/>
    </xsl:function>
    
    <xsl:function name="dpc:serialise">
     <xsl:param name="n"/>
     <xsl:apply-templates select="$n" mode="verb"/>
    </xsl:function>
    
    <xsl:template mode="verb" match="*">
     <xsl:value-of select="concat('&lt;',name())"/>
     <xsl:value-of select="@*/concat(' ',name(),'=&quot;',.,'&quot;')"/>
     <xsl:value-of select="'&gt;'"/>
     <xsl:apply-templates mode="verb"/>
     <xsl:value-of select="concat('&lt;/',name(),'&gt;')"/>
    </xsl:template>
    
    
    
    <xsl:template match="foo">
     <div>
      <xsl:copy-of select="@*"/>
      <xsl:value-of select="."/>
     </div>
    </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my aspx file, I have some code that looks like this: <script type=text/javascript>
I have a JAVASCRIPT array that looks like this: postarray['min_price'] = 120000; postarray['max_price'] =
I've got some JavaScript in an ASP.NET page that looks like this: var list
I have a .htaccess in my root of website that looks like this: RewriteEngine
I have an xml document that looks something like this <?xml version=1.0 encoding=UTF-8?> <mapPoints>
I have a javascript file that reads another file which may contain javascript fragments
I have a lengthy JavaScript file that passes JSLint except for used before it
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
I have some code in a javascript file that needs to send queries back
I have a .tag file that requires a JavaScript library (as in a .js

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.