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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:00:32+00:00 2026-06-18T07:00:32+00:00

I would like to do a string replacement with a value from a variable,

  • 0

I would like to do a string replacement with a value from a variable, like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str" >
<xsl:variable name="my-variable">bar</xsl:variable>
<xsl:template match="text()">
    <xsl:value-of select="str:replace( . ,'foo', $my-variable )"/>
</xsl:template>
</xsl:stylesheet>

When I run this on a file, e.g.,

<?xml version="1.0" encoding="utf-8"?>
<root>foobar</root>

I this error from xsltproc / libxslt

XPath error : Invalid type
xmlXPathCompiledEval: evaluation failed
runtime error: file C:/Users/Adam/Documents/WakhiLD/XSL/replace.xsl line 6 element value-of
XPath evaluation returned no result.

It seems reasonable to use variables in function calls, so I am at a loss as to what I should be doing.

  • 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-18T07:00:34+00:00Added an answer on June 18, 2026 at 7:00 am

    Simply use <xsl:variable name="my-variable" select="'bar'"/> and it should work. You are currently creating variable of type result tree fragment and it looks as if the extension function is not doing any conversion to a string when passed such an argument. But simply creating a string variable as shown above should solve it.

    If you really need to create the variable as a result tree fragment then try converting to a string explicitly, as in <xsl:value-of select="str:replace( . ,'foo', string($my-variable) )"/>.

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

Sidebar

Related Questions

I would like to remove all twitter nicknames (@xxx) from a string like this:
I have a string Like this: MyText (1,151) I would like to get with
I have a string like this: String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] I would like
I would like to convert this string foo_utf = u'nästy chäräctörs with å and
I would like to do a string replacement in all items in an array.
I would like to generate a regex for a string like S67-90. I used
I have an alphanumeric string like below, $string_1 = a4nas60dj71wiena15sdl1131kg12b and would like to
I have a string would like everything after the last / to be returned.
I would like to take a string representation of a set and parse it.
I would like to separate my string by spaces, commas, periods (ie. punctuations). 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.