Click to See Complete Forum and Search --> : About xml:space and xsl:space


BBShot
04-05-2003, 07:57 PM
Hi, I am new to XML. Maybe you guys can help me.

I have two files "whitespaces.xml" and "whitespaces.xsl". Please check the listings of these files at the end of the post.

I use IE6.0 to open my XML file. I'd like the output to be "One Two Three Four" but the current output is "One TwoThree Four" (no space between two and three). I also tried this code with Mozilla and it worked as I wished. However, I need it to work with IE too.

I've done a bit of research and I found that the attribute xml:space was what I've been looking for. Unfortunatly, I didn't get to make it work properly.

When I modify the <p> tag in my XML file to <p xml:space="preserve">, it works great but when I try applying this attribute in my XSL file, IE seems to simply ignore it.

Here's a list of possible solution that didn't work for me:
1) <xsl:template match="p" xsl:space="preserve">
2) <p><xsl:apply-templates xsl:space="preserve"/></p>
3) <!DOCTYPE root [ <!ATTLIST p xml:space (default|preserve) #FIXED "preserve"> ]>

Thank you so much in advance!!!

[whitespaces.xml] listing:
----------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="whitespaces.xsl"?>

<root>

<p>

One <i>Two</i> <link>Three</link> Four

</p>

</root>

----------------------------------

[whitespaces.xsl] listing:
----------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xsl:stylesheet>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>

<head>
<title>Test page</title>
</head>

<body>

<xsl:apply-templates/>

</body>
</html>
</xsl:template>

<xsl:template match="p">
<p><xsl:apply-templates/></p>
</xsl:template>

</xsl:stylesheet>
----------------------------------

khalidali63
04-06-2003, 08:24 AM
just a suggestion,did you try using a character ref or html entity for space

char ref =
entity anme = &sp;

I know that char ref would work for sure

Khalid

BBShot
04-06-2003, 10:00 PM
You're right, this works too but I don't want a patching solution.

I don't want to bother checking if each space is located between two tags alone or with other characters.

In addition to that, I'm pretty sure there is a clearer way to accomplish that so I prefer going for the "xml:space".

Thanks for your anwser!

khalidali63
04-07-2003, 12:39 AM
Depending upon your modal,
here is one way of doing it.
In the XML file
if you want a <p> tag to maintain the whitespacing then
<p xml:space="preserve"> should take care of that.

<xsl:preserve-space elements="p"/>

Cheers

Khalid

BBShot
04-15-2003, 02:11 PM
Again, your solution works perfectly! However I don't want to modify my XML files unless the code can be added in the DTD (and only in the DTD).

I know I make things a bit complicated. I'm sorry. ;)

khalidali63
04-15-2003, 02:52 PM
ohhkkaayy..

Read up on this element.
<xslreserve-space elements="element element"/>
you can use just this to preserve space as well .

in the above element will be the name of the element in which ou want to preserve spacing.

Cheers

Khalid