[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to trim leading and trailing spaces in xsl:at

Subject: Re: How to trim leading and trailing spaces in xsl:attribute?
From: JBryant@xxxxxxxxx
Date: Wed, 25 May 2005 12:54:10 -0500
xsl trim
Hi, David,

Take a peek at the normalize-space function. You can use it like this:

<xsl:attribute name="myAttribute"><xsl:value-of 
select="normalize-space(widget)"/></xsl:attribute>

A useful shortcut, by the way:

<xsl:attribute name="myAttribute" select="normalize-space(widget)"/>

Speaking of shortcuts, you can use an Attribute Value Template (AVT) for a 
lot of these kinds of issues. For example:

<xsl:element name="something">
  <xsl:attribute name="myAttribute"><xsl:value-of 
select="normalize-space(widget)"/></xsl:attribute>
</xsl:element>

can often be replaced by:

<something myAttribute="{normalize-space(widget)}"/>

Of course, you occasionally must use the more verbose way, such as for 
attributes that are present sometimes and absent other times.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




"Karr, David" <david.karr@xxxxxxxx> 
05/25/2005 12:41 PM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
<xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
cc

Subject
 How to trim leading and trailing spaces in xsl:attribute?






I have an "<xsl:attribute>" element in my stylesheet, and its value is
an "<xsl:value-of>" reference which then calls an XPATH function.  The
resulting single line is a little ugly.  I'd like to format the line so
it's a little more readable.  Unfortunately, I appear to be limited by
the semantics of the "<xsl:attribute>" element.  It does not trim
leading and trailing spaces, and it encodes any newlines found in the
resulting value.

I'm using JDK 1.4.2, in case there are constraints in the native TRAX
implementation inherent in that.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.