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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:44:19+00:00 2026-06-15T16:44:19+00:00

I have a HTML page with some Javascript that I’m trying to parse with

  • 0

I have a HTML page with some Javascript that I’m trying to parse with XSLT 1.0. I want to modify a URL that’s inside the Javascript to make the path absolute instead of relative.

The Javascript-code looks roughly like this:

<html>
    <head>
        <script>
            function login() {
                window.location = '{@myBase}/myloginpage';
            }
        </script>
    </head>

    <body>
     ...
    </body>
</html>

I want the ‘{@myBase}’ to be replaced with my domain. I feel that I’m very much off course.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:proxy="java:senselogic.sitevision.portlet.proxy.web.ProxyFunctions" 
   extension-element-prefixes="proxy">


   <xsl:import href="template.xsl"/>

    <xsl:template match="//script/text()">
        <xsl:variable name="mypath">
          <xsl:call-template name="string-replace-all">
            <xsl:with-param name="text"><xsl:value-of select="{@myBase}"/></xsl:with-param>
            <xsl:with-param name="replace">{@myBase}</xsl:with-param>
            <xsl:with-param name="by">http://www.mydomain.com</xsl:with-param>
          </xsl:call-template>
        </xsl:variable>
    </xsl:template>    



    <xsl:template name="string-replace-all">
      <xsl:param name="text" />
      <xsl:param name="replace" />
      <xsl:param name="by" />
      <xsl:choose>
        <xsl:when test="contains($text, $replace)">
          <xsl:value-of select="substring-before($text,$replace)" />
          <xsl:value-of select="$by" />
          <xsl:call-template name="string-replace-all">
            <xsl:with-param name="text"
            select="substring-after($text,$replace)" />
            <xsl:with-param name="replace" select="$replace" />
            <xsl:with-param name="by" select="$by" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$text" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>    
</xsl:stylesheet>
  • 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-15T16:44:20+00:00Added an answer on June 15, 2026 at 4:44 pm

    Actually, you are not far off.

    Firstly, you are defineing a variable <xsl:variable name="mypath"> to hold the results of the call-template but not actually doing anything with it. I don’t think you need to wrap it in a variable declaration at all.

    Secondly, you are not passing the correct value to the text parameter. Instead of doing this

    <xsl:with-param name="text"><xsl:value-of select="{@myBase}"/></xsl:with-param>
    

    Do this

    <xsl:with-param name="text"><xsl:value-of select="."/></xsl:with-param>
    

    Or better still, this:

    <xsl:with-param name="text" select="."/>
    

    Try this XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:proxy="java:senselogic.sitevision.portlet.proxy.web.ProxyFunctions" extension-element-prefixes="proxy">
        <xsl:param name="domain" select="'http://www.mydomain.com'"/>
    
        <xsl:template match="//script/text()">
            <xsl:call-template name="string-replace-all">
                <xsl:with-param name="text" select="."/>
                <xsl:with-param name="replace" select="'{@myBase}'" />
                <xsl:with-param name="by" select="$domain"/>
            </xsl:call-template>
        </xsl:template>
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template name="string-replace-all">
            <xsl:param name="text"/>
            <xsl:param name="replace"/>
            <xsl:param name="by"/>
            <xsl:choose>
                <xsl:when test="contains($text, $replace)">
                    <xsl:value-of select="substring-before($text,$replace)"/>
                    <xsl:value-of select="$by"/>
                    <xsl:call-template name="string-replace-all">
                        <xsl:with-param name="text" select="substring-after($text,$replace)"/>
                        <xsl:with-param name="replace" select="$replace"/>
                        <xsl:with-param name="by" select="$by"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$text"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>
    

    (Note that I have also set your domain to be a parameter)

    When applied to your XHTML, the following is output

    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html">
    <script>
                function login() {
                    window.location = 'http://www.mydomain.com/myloginpage';
                }
            </script></head>
    <body>
         ...
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with some very basic examples that use HTML/CSS/JavaScript. I'd like
I have an HTML page that contains some filenames that i want to download
I have a mystery.html page that loads some javascript (as well as mootools). I
I have a HTML page that contains a flash file and some a JavaScript
I have an html page that calls some javascript and jQuery functions and also
My html page loads beautifully, but I have some JavaScript that adds a few
I have a 404.html page, but in some cases I want to be able
I have create a HTML page with some JavaScript code. Here is the code
I have a html component that includes some javascript. The component is a file
I have custom JSP tags that generate some HTML content, along with some javascript

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.