472,794 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

Whitespace in <xsl:attribute> tags

My XSLT files have many occurrences of this general pattern:

<a>
<xsl:attribute name="href">
<xsl:value-of select="xyz" />
</xsl:attribute>
</a>

When I execute an XSL transform, the resulting HTML looks like this:

<a href="xyz%0A%09%09">

.... because *everything* between the opening and closing attribute tags
is being included, even the carriage return after the opening attribute
tag and the tabs before the value-of tag.

Is there a way to avoid this behavior? I tried adding
<xsl:strip-space elements="*"/at the top of the file, but it appeared to
have no effect.

--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Jul 2 '08 #1
5 3830
John Gordon wrote:
My XSLT files have many occurrences of this general pattern:

<a>
<xsl:attribute name="href">
<xsl:value-of select="xyz" />
</xsl:attribute>
</a>

When I execute an XSL transform, the resulting HTML looks like this:

<a href="xyz%0A%09%09">

... because *everything* between the opening and closing attribute tags
is being included, even the carriage return after the opening attribute
tag and the tabs before the value-of tag.

Is there a way to avoid this behavior? I tried adding
<xsl:strip-space elements="*"/at the top of the file, but it appeared to
have no effect.
Which XSLT processor are you using?
For the stylesheet itself (see http://www.w3.org/TR/xslt#strip) "the set
of whitespace-preserving element names consists of just xsl:text" so the
white space between those xsl element should not result in white space
in the result tree.

Obviously the snippet you posted can be reduced to
<a href="{xyz}">
</a>
using an literal result element and an attribute value template but what
you have should not result in whitespace problems.

Are you sure the whitespace and the escaping does not result from
evaluating xyz and applying HTML href escaping?


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 2 '08 #2
In article <g4**********@reader1.panix.com>,
John Gordon <go****@panix.comwrote:
>My XSLT files have many occurrences of this general pattern:

<a>
<xsl:attribute name="href">
<xsl:value-of select="xyz" />
</xsl:attribute>
</a>

When I execute an XSL transform, the resulting HTML looks like this:

<a href="xyz%0A%09%09">
Do you have xml:space="preserve" on some ancestor of the <xsl:attribute>
element?

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Jul 2 '08 #3
In <48**********************@newsspool2.arcor-online.netMartin Honnen <ma*******@yahoo.dewrites:
Which XSLT processor are you using?
I'm using the libxslt package in python.
Obviously the snippet you posted can be reduced to
<a href="{xyz}">
</a>
Yes, I've changed to this shorthand method and it has helped.
Are you sure the whitespace and the escaping does not result from
evaluating xyz and applying HTML href escaping?
I thought it might be an href escaping issue, but then I noticed the
same thing happening when I was setting a variable and then using the
value in a hidden form input element, like so:

<xsl:variable name="actionType">
<xsl:choose>
<xsl:when test="something">
someValue
</xsl:when>
<xsl:otherwise>
someOtherValue
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

....

<form>
<input type="hidden" name="actionType">
<xsl:attribute name="value">
<xsl:value-of select="$actionType" />
</xsl:attribute>
</input>
</form>

The value of the form element contained the embedded newline and tabs.
When I changed the hidden form element to use the shorthand {} notation
the problem still persisted; it was only fixed by editing the variable
declaration and removing all the whitespace between the beginning and
ending <xsl:whenand <xsl:otherwisetags, like so:

<xsl:variable name="actionType">
<xsl:choose>
<xsl:when test="something">someValue</xsl:when>
<xsl:otherwise>someOtherValue</xsl:otherwise>
</xsl:choose>
</xsl:variable>

--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Jul 2 '08 #4
In <g4***********@pc-news.cogsci.ed.ac.ukri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
My XSLT files have many occurrences of this general pattern:

<a>
<xsl:attribute name="href">
<xsl:value-of select="xyz" />
</xsl:attribute>
</a>

When I execute an XSL transform, the resulting HTML looks like this:

<a href="xyz%0A%09%09">
Do you have xml:space="preserve" on some ancestor of the <xsl:attribute>
element?
No, not that I know of. (I inherited this project from someone else; it's
possible that such an element is present and I'm just not aware of it.)

--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Jul 2 '08 #5
<xsl:when test="something">
someValue
</xsl:when>
If someValue is literal text, the whitespace is assumed to be
meaningful. See XML's rules regarding "whitespace in element content";
whitespace adjacent to non-whitespace is assumed to be part of the same
text as that non-whitespace and should be retained. Your original
question was about
<input type="hidden" name="actionType">
<xsl:attribute name="value">
<xsl:value-of select="$actionType" />
</xsl:attribute>
</input>
Here the whitespace is adjacent only to an element, and hence XSLT
should conclude that it's just stylesheet indentation and can be
discarded, unless you have instructed it otherwise.

If your XSLT processor isn't giving you the expected behavior, it may be
time to switch processors. Or to send a bug report to its authors and
see if they can tell you what you're doing that they didn't anticipate.
Jul 2 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ray Tayek | last post by:
hi, trying to use an xslt to make an xslt. trying something like: <?xml version="1.0" encoding="UTF-8"?> <?xmlspysamplexml H:\java\projects\spy1\spy\inputDocumentMap.xml?> <xsl:stylesheet...
3
by: Rupa | last post by:
Hi, I'm trying to write an xslt to convert an email in xml format to a new xml format. <descr> <xsl:choose> <xsl:value-of select="body"> </xsl:value-of select> <xsl:when test=" <xsl:value-of...
1
by: Matt | last post by:
For example, how to represent hyperlink in XSL? I want to add hyperlink in XSL. i.e. I need to generate <A HREF="http://mypage.html">home page</A> in HTML. I tried the following approaches but...
3
by: Blaise Garant | last post by:
Hi I've made a stylesheet to transform my data into XSL-FO. This stylesheet used to work with MSXSL 4.0 but I've got some issues in ..NET. First, I changed removed all the "node-set()" function...
3
by: b0yce | last post by:
Hi Group, I think I have found a problem with the <xsl:element> when being transformed by the .NET xmlTransform class. When using XmlSpy for development and debugging, the <xsl:number>...
2
by: jd | last post by:
Hi, I have an xsl as below. I am trying to loop using <xsl:for-each> and in the select attribute of <xsl:for-each> i am getting the nodeset from the external javascript function in the <CDATA>...
5
by: Luke Vogel | last post by:
Hi all, Probably a really basic question, but I cant find an answer ... I have an xml file of books something like: <product> <isbn>0-735-61374-5</isbn> <title>Microsoft Visual Basic Step By...
2
by: ismailc | last post by:
Hi, I'm using this HTML code to set my tooltip. I get it working in HTML then i incorporated it in xslt. I got it to work for only the first field value then i realized i was not changing the...
2
Dormilich
by: Dormilich | last post by:
Hi, my goal is to have a stylesheet, where I can change the encoding attribute of the <xsl:output> element (one shall have utf-8 and the other latin-1). is there any way to set this via a...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.