473,698 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSL and Whitespace

Hello all,

how does xsl handle white space?
I know you can set domething like this
for nice indentation:

<xsl:output method="xhtml" indent="yes"/>

But know i have xsl code like this:

<a>
<xsl:attribut e name="href">
<xsl:value-of select="$absolu te_url"/>/index.php?page= <xsl:value-of
select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of
select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
</a>
But that should transform to someting like this:

<a href="http://localhost/index.php?page= pages/medewerker.page .xml&id=42">
</a>

Not to someting like this:

<a
href="http://localhost/index.php?page= pages/medewerker.page .xml%0a%09%09%0 9%09&amp;%0a%09 %09%09%09%09%09 %09%09%09id%0a% 09%09%09%09%09% 09%09%09=42">
</a>
How do is solve my problem??
And why is &amp not recognised? How should i define entities?
Note, i have an xsd but i do not use it to validate documents, and the
xml documents do not say wich scheme they are. So how can i define &amp;
=& without xsd?!?!
Jul 20 '05 #1
8 2936
> <a>
<xsl:attribut e name="href">
<xsl:value-of select="$absolu te_url"/>/index.php?page= <xsl:value-of
select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of
select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
</a>
that should transform to someting like this:

<a href="http://localhost/index.php?page= pages/medewerker.page .xml&id=42">
</a>

Not to someting like this:

<a
href="http://localhost/index.php?page= pages/medewerker.page .xml%0a%09%09%0 9%09&amp;%0a%09 %09%09%09%09%09 %09%09%09id%0a% 09%09%09%09%09% 09%09%09=42">
</a>
How do is solve my problem??
Hi,

Use something like this:
<xsl:variable name="href" >
/index.php?page= <xsl:value-of select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of select="page:va lue"/>
</xsl:for-each>
</xsl:variable>
<a href="{normaliz e-space($href)}">
<xsl:apply-templates select="node()[not(self::page: var)]" mode="ignore"/>
</a>
And why is &amp; not recognised? How should i define entities?

Actually it is being recognised as the entity for '&'. But, when serializing the output, the processor escapes the '&' symbol back to '&amp;'. In the past I also try to deal with this, but I haven't found any solution yet. Even not with DTD's or XSD's. The XSLT 1.0 clearly states that it is illegal to disable output escaping in output nodes other than text nodes. (http://www.w3.org/TR/xslt.html#disable-output-escaping). XSLT 2.0 might bring a solution...

regards,

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
Joris Gillis wrote:
<a>
<xsl:attribut e name="href">
<xsl:value-of select="$absolu te_url"/>/index.php?page= <xsl:value-of
select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of
select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
</a>
that should transform to someting like this:

<a
href="http://localhost/index.php?page= pages/medewerker.page .xml&id=42">
</a>

Not to someting like this:

<a
href="http://localhost/index.php?page= pages/medewerker.page .xml%0a%09%09%0 9%09&amp;%0a%09 %09%09%09%09%09 %09%09%09id%0a% 09%09%09%09%09% 09%09%09=42">

</a>
How do is solve my problem??

Hi,

Use something like this:
<xsl:variable name="href" >
/index.php?page= <xsl:value-of select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of
select="page:va lue"/>
</xsl:for-each>
</xsl:variable>
<a href="{normaliz e-space($href)}">
<xsl:apply-templates select="node()[not(self::page: var)]" mode="ignore"/>
</a>
And why is &amp; not recognised? How should i define entities?


Actually it is being recognised as the entity for '&'. But, when
serializing the output, the processor escapes the '&' symbol back to
'&amp;'. In the past I also try to deal with this, but I haven't found
any solution yet. Even not with DTD's or XSD's. The XSLT 1.0 clearly
states that it is illegal to disable output escaping in output nodes
other than text nodes.
(http://www.w3.org/TR/xslt.html#disable-output-escaping). XSLT 2.0
might bring a solution...

regards,


Hey joris,

You know alot about xml xsl and xpath,
but where does your knowledge come from?

from a book?
from the internet?

I've learned xml xpath and xsl from the internet from sites like
w3schools and from the w3c specifications.

But some problems i cannot solve.

So do have advice for me to learn more about xsl and xpath?
Url or book?

Anyways, thanks for your help.
Jul 20 '05 #3
> So do have advice for me to learn more about xsl and xpath?
Url or book?


I found 'inside XSLT' quite useful. But I cannot compare as I never read another book on the topic. And the book might be outdated now.

A site where all XSL and Xpath tricks are bundled would be very handy, but I never found such site.

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #4


Tjerk Wolterink wrote:

I've learned xml xpath and xsl from the internet from sites like
w3schools and from the w3c specifications.

But some problems i cannot solve.

So do have advice for me to learn more about xsl and xpath?
Url or book?


Many problems are solved, check the FAQ at
http://www.dpawson.co.uk/xsl/index.html
There is also
http://www.jenitennison.com/xslt/

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #5
Hi Tjerk,

The reason you are seeing whitespace in the attribute output is because you
are using implied output text. As soon as you use implied output text -
that implied output text will also include any whitespace (inc. tabs, CRs
etc.).

You can overcome this by using explicit output text (and it's best to get
into the habit of using explicit output text), e.g.

<a>
<xsl:attribut e name="href">
<xsl:value-of select="$absolu te_url"/>
<xsl:text>/index.php?page= </xsl:text>
<xsl:value-of select="@page"/>
<xsl:for-each select="page:va r">
<xsl:text>&amp; </xsl:text>
<xsl:value-of select="page:na me"/>
<xsl:text>=</xsl:text>
<xsl:value-of select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
</a>

The ampersands are being correctly recognised and are being URL encoded
according to the HTML/XHTML specs.

HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Tjerk Wolterink" <tj***@wolterin kwebdesign.com> wrote in message
news:41******** *************** @news.wanadoo.n l...
Hello all,

how does xsl handle white space?
I know you can set domething like this
for nice indentation:

<xsl:output method="xhtml" indent="yes"/>

But know i have xsl code like this:

<a>
<xsl:attribut e name="href">
<xsl:value-of select="$absolu te_url"/>/index.php?page= <xsl:value-of
select="@page"/>
<xsl:for-each select="page:va r">
&amp;<xsl:va lue-of select="page:na me"/>=<xsl:value-of
select="page:va lue"/>
</xsl:for-each>
</xsl:attribute>
</a>
But that should transform to someting like this:

<a href="http://localhost/index.php?page= pages/medewerker.page .xml&id=42">
</a>

Not to someting like this:

<a
href="http://localhost/index.php?page= pages/medewerker.page .xml%0a%09%09%0 9%
09&amp;%0a%09%0 9%09%09%09%09%0 9%09%09id%0a%09 %09%09%09%09%09 %09%09=42"> </a>
How do is solve my problem??
And why is &amp not recognised? How should i define entities?
Note, i have an xsd but i do not use it to validate documents, and the
xml documents do not say wich scheme they are. So how can i define &amp;
=& without xsd?!?!

Jul 20 '05 #6
> The reason you are seeing whitespace in the attribute output is because you
are using implied output text. As soon as you use implied output text -
that implied output text will also include any whitespace (inc. tabs, CRs
etc.).

You can overcome this by using explicit output text (and it's best to get
into the habit of using explicit output text), e.g.
The ampersands are being correctly recognised and are being URL encoded
according to the HTML/XHTML specs.


Hi,

Setting the output method to 'text' may solves the ampersand and the superfluous wittespaces, but the 'a' element and it's attribute will not be outputted. (http://www.w3.org/TR/xslt.html#secti...-Output-Method)
I don't think it makes sense to output 'text' if you're actually dealing with 'html'. Moreover you'd have to have to strinyfy all element and attributes throughout the stylesheet, a really bad idea if you ask me.
If this 'hack' really is the only way around it, don't you agree that this is a shortcomming in the XSLT1.0 Recommendation?

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #7
Hi,
Hi,

Setting the output method to 'text' may solves the ampersand and the superfluous wittespaces, but the 'a' element and it's attribute will not be
outputted. (http://www.w3.org/TR/xslt.html#secti...-Output-Method) I don't think it makes sense to output 'text' if you're actually dealing with 'html'. Moreover you'd have to have to strinyfy all element and
attributes throughout the stylesheet, a really bad idea if you ask me. If this 'hack' really is the only way around it, don't you agree that this is a shortcomming in the XSLT1.0 Recommendation?

I did not mention the output method at all! - merely pointed to the correct
and safe way of outputting text nodes using the <xsl:text> instruction.
This is no hack whatsoever, and there is not shortcomming in the W3 rec
regarding this issue. It is known by all seasoned XSLT programmers that the
first step towards taking firm control of whitespace (in whatever output
mode) is to avoid using implicit text node output and opt for using explicit
text node output using the <xsl:text> instruction. The <xsl:text>
instruction is there for a reason - one of which being so that explicit
output text nodes can be differentiated from whitespace text nodes in the
stylesheet that are merely there to 'prettify' the stylesheet for
readability (which might otherwise be assumed by the XSLT transformation as
text nodes for output).

I can only suggest you re-read my original posting again ;) If you read it
carefully you will notice there is no mention of the output mode and gives
clear example code on using the <xsl:text> instruction.

Cheers
Marrow

"Joris Gillis" <ro**@pandora.b e> wrote in message
news:op******** ******@news.pan dora.be...
The reason you are seeing whitespace in the attribute output is because you are using implied output text. As soon as you use implied output text -
that implied output text will also include any whitespace (inc. tabs, CRs etc.).

You can overcome this by using explicit output text (and it's best to get into the habit of using explicit output text), e.g.
The ampersands are being correctly recognised and are being URL encoded
according to the HTML/XHTML specs.


Hi,

Setting the output method to 'text' may solves the ampersand and the

superfluous wittespaces, but the 'a' element and it's attribute will not be
outputted. (http://www.w3.org/TR/xslt.html#secti...-Output-Method) I don't think it makes sense to output 'text' if you're actually dealing with 'html'. Moreover you'd have to have to strinyfy all element and
attributes throughout the stylesheet, a really bad idea if you ask me. If this 'hack' really is the only way around it, don't you agree that this is a shortcomming in the XSLT1.0 Recommendation?
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum

Jul 20 '05 #8
> I can only suggest you re-read my original posting again ;) If you read it
carefully you will notice there is no mention of the output mode and gives
clear example code on using the <xsl:text> instruction.


Sorry about that, I shouldn't have sent such hastely reaction without reading your mail carefully. You're absolutely right about the 'xsl:text' element.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #9

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

Similar topics

9
90009
by: Thomas Mlynarczyk | last post by:
Which is the simplest way to remove all whitespace from a string? Is there a simpler method than a regex replace? Or how can I tell a regex pattern to ignore all whitespace in my subject string? There is a global modifier to ignore all spaces in the pattern, but I couldn't find one for ignoring spaces in the subject string. Do I really have to either do a preg_replace to remove all whitespace or stick a lot of \s* into my search pattern? ...
2
2156
by: Wolfgang Jeltsch | last post by:
Hello, it is often convenient to insert whitespace into an XML document in order to format it nicely. For example, take this snippet of a notional DocBook XML document: <para> This is a longer paragraph. With <wordasword>longer</wordasword> I mean that it contains more than one sentence.
2
2023
by: Carlitos | last post by:
Hi there, A class in Xerces J-API (Java) called TextImpl contains a property that returns whether the text is ignorable whitespace (http://xml.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/TextImpl.html#isIgnorableWhitespace()). ; I guess when they refer to "ignorable whitespace" in Java we may interpret that as an "insignificant whitespace" in .NET. Am I correct to say that? So, I need to manually convert some Java code to C#,...
2
1943
by: Carlitos | last post by:
Hi there, A class in Xerces J-API (Java) called TextImpl contains a property that returns whether the text is ignorable whitespace (http://xml.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/TextImpl.html#isIgnorableWhitespace()). I guess when they refer to "ignorable whitespace" in Java we may interpret that as an "insignificant whitespace" in .NET. Am I correct to say that? So, I need to manually convert some Java code to C#,...
0
2247
by: Shan Plourde | last post by:
Hi everyone, I have been using various regular expressions with the ASP.NET RegularExpressionValidator for quite some time. In general it works very well. One of the common regex's that I use follows: ValidationExpression = "^\d{0,3}(\.\d{0,4})?$" The purpose of this one is to validate that numeric values input follow the syntax 999.9999. This works well. But, one thing that I have never tested previously (which has now been uncovered...
3
2621
by: David Pratt | last post by:
Hi. I am splitting a string on a non whitespace character. One or more whitespace characters can be returned as items in the list. I do not want the items in the list that are only whitespace (can be one or more characters of whitespace) and plan to use string.strip on those items that are not only whitespace (to remove any whitespace from front or back of items). What kind of efficient test can I use to obtain only list items returned...
56
3540
by: infidel | last post by:
Where are they-who-hate-us-for-our-whitespace? Are "they" really that stupid/petty? Are "they" really out there at all? "They" almost sound like a mythical caste of tasteless heathens that "we" have invented. It just sounds like so much trivial nitpickery that it's hard to believe it's as common as we've come to believe.
9
2554
by: amattie | last post by:
Does anyone have any idea on how I can strip the extra whitespace in the XML that shows up when I receive a response from an ASP.NET 2.0 webservice? This has been discussed before, but no one has ever come up with a good answer to what seems like such a common question. ...
5
3905
by: John Gordon | last post by:
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:
13
27954
by: Chaim Krause | last post by:
I am unable to figure out why the first two statements work as I expect them to and the next two do not. Namely, the first two spit the sentence into its component words, while the latter two return the whole sentence entact. import string from string import whitespace mytext = "The quick brown fox jumped over the lazy dog.\n" print mytext.split()
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.