xsl-list
[Top] [All Lists]

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

2005-05-25 12:06:28
I use XSLT 2.0, so my useful shortcut works for me.

Also, that was intentional. I have often had trouble with line breaks in 
XSLT, so I generally put those kinds of structures on a single line. Most 
of the time, it's just because I'm fussy about how the output appears, but 
it does occasionally make a significant difference.

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




"Karr, David" <david(_dot_)karr(_at_)wamu(_dot_)net> 
05/25/2005 01:28 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com


To
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
cc

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






Using "normalize-space()" in my "xsl:value-of" element doesn't address
the issue.  It's not spaces in the variable I'm referencing that is an
issue, it's the spaces that I produce by adding a newline after
"<xsl:attribute ...>".  I thought your "useful shortcut" would solve my
problem, but that doesn't work for me.  It fails, saying "select" is not
a valid attribute for "xsl:attribute".

I would guess the only way to come close to addressing this is adding
the newline after "<xsl:value-of", as you did in your reply (either
intentionally or unintentionally), instead of after "<xsl:attribute
...>".

-----Original Message-----
From: JBryant(_at_)s-s-t(_dot_)com [mailto:JBryant(_at_)s-s-t(_dot_)com] 

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(_dot_)karr(_at_)wamu(_dot_)net> 
05/25/2005 12:41 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com


To
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
cc

Subject
[xsl] 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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--