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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:43:31+00:00 2026-05-13T01:43:31+00:00

Im trying to use XSL and Xpath functions to remove all the white space

  • 0

Im trying to use XSL and Xpath functions to remove all the white space from a XML attribute called name and make it lower case. At the moment i have something like

 <xsl:variable name="linkName">
 <xsl:value-of select="normalize-space(name)"/>
 </xsl:variable>

This removes the white space at the beginning and end but not the middle. Any suggestions?

What is the best practice for handling and altering XML data as it seems that you can use

<xsl:value-of select="x"/>  

placed directly in the HTML

or

<xsl:attribute name="y">
<xsl:value-of select="x"/>

or use a

<xsl:variable name="x">

I’m not really sure of the differences or when each should be used. Any help is much appreciated.

Ally

  • 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-13T01:43:32+00:00Added an answer on May 13, 2026 at 1:43 am

    As Tim Robinson points out, translate will do the trick. (I wouldn’t call it a “hack,” but then I’ve long been at the identifying-with-my-torturers stage of my relationship with XSLT.) Your code will be a lot more readable if you use something like this:

    <xsl:variable name="uc" value="ABCDEFGHIJKLMNOPQRSTUVWXYZ"/>
    <xsl:variable name="lc" value="abcdefghijklknopqrstuvwxyz"/>
    <xsl:variable name="ws" value=" &#13;&#10;&#09"/>
    

    …which is part of the globals.xslt file that I include at the top of most transforms I write. Then this:

    <xsl:value-of select="translate(x, concat($uc, $ws), $lc)"/>
    

    translates each upper-case letter into its lower-case equivalent, and each whitespace character into nothing.

    Usually the reason you use xsl:variable is to make code more readable (as in the above example), or to store intermediate results that can’t otherwise be effectively calculated. A fourth way of getting data into the output is one you didn’t mention, and that’s pretty darned useful: the attribute value template. All of these do the same thing:

    <link>
       <xsl:attribute name="name">
          <xsl:value-of select="translate(name, concat($uc, $ws), $lc)"/>
       </xsl:attribute>
    </link>
    
    <link>
        <xsl:attribute name="name" value="translate(name, concat($uc, $ws), $lc)"/>
    </link>
    
    <xsl:variable name="linkName" value="translate(name, concat($uc, $ws), $lc)"/>
    <link name="{$linkName}"/>
    

    In this particular case, it’s arguable which of the last two is simpler and clearer. Most of the time, though, it’s not: separating the calculation of values from how they get inserted into the output makes both easier to understand, as does using an AVT instead of more verbose XSLT constructs that do the same thing.

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

Sidebar

Related Questions

I am trying to get some xpath from xsl variable using xsl ver 1.0
I'm trying to use XSL-stylesheets in order to transform some generated XML-data to HTML-output.
I'm trying to use XML files and XSL stylesheets instead of ordinary phtml templates
Trying to use an excpetion class which could provide location reference for XML parsing,
I trying to use ImageInfo and Jython to get information from a image on
Trying to use a guid as a resource id in a rest url but
While trying to use LINQ to SQL I encountered several problems. I have table
I' trying to use a Linq query to find and set the selected value
I'm trying to use svnmerge.py to merge some files. Under the hood it uses
I've been trying to use SQLite with the PDO wrapper in PHP with mixed

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.