Problems with whitespace in output document

  • Thread starter Michael Kragh Pedersen
  • Start date
M

Michael Kragh Pedersen

I have made an XSLT document, looking like this.

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput indent="yes" method="text"/>
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<xsl:apply-templates/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

Nothing fancy about that, just writing out the elements. So I get this
output, when I see it in the browser (Mozilla on Linux).

A
B
E
F

C
D

But I want for it to be flattened, so all of the elements are aligned
left. I feel like, I have tried everything, with xsl:eek:utput and
normalize-string(), and I have no idea, how to remove the whitespace.

I also tried removing all the whitespace from my XML document, that
didn't help either.

Anybody with some good ideas?

Michael K. P.
 
D

David Carlisle

Michael Kragh Pedersen said:
I have made an XSLT document, looking like this.

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput indent="yes" method="text"/>

If you use the text output method, there is no indentation possible also
all element nodes in the result tree will be discarded, so you could
drop HTML etc from the code below and get the same result.
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<xsl:apply-templates/>

Note this also applies templates to text nodes so will copy any
indentation and other white space to the output.
</BODY>
</HTML>
</xsl:template>
<xsl:template match="*">
<xsl:apply-templates/> similarly this.
</xsl:template>
</xsl:stylesheet>


Perhaps you want to add <xsl:strip-space elements="*"/> so that white
space nodes in the input are ignored, but if you output using the html
output method then unless you use <pre> or equivalent css then newlines
in the result won't render as newlines anyway si teh result should not
look like the result you show below when rendered in the browser.
Nothing fancy about that, just writing out the elements. So I get this
output, when I see it in the browser (Mozilla on Linux).

A
B
E
F

C
D

But I want for it to be flattened, so all of the elements are aligned
left. I feel like, I have tried everything, with xsl:eek:utput and
normalize-string(), and I have no idea, how to remove the whitespace.

I also tried removing all the whitespace from my XML document, that
didn't help either.

Anybody with some good ideas?

Michael K. P.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top