XSL ignores my whitespace even with the tag

2019-04-21 01:14发布

I'm making a header in my XSL code that includes multiple fields of information, i.e. "Name: Bob Birthdate: January 1 1900," etc. I enclosed them in tags as such:

<xsl:text>    Gender: Male    </xsl:text> 

But on the page, the whitespace around Gender/Male is being ignored. Is there something I'm missing?

Thanks in advance.

5条回答
看我几分像从前
2楼-- · 2019-04-21 01:29

You need to add &nbsp; instead of spaces. To get more than 1 space

<xsl:text><![CDATA[&nbsp;&nbsp;&nbsp; Gender: Male &nbsp;&nbsp;&nbsp;]]></xsl:text>

查看更多
时光不老,我们不散
3楼-- · 2019-04-21 01:30

This not a strict XSLT question, as XSLT does not eat your white space. This transformation

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <foo>
      <xsl:text>    Gender: Male    </xsl:text>
    </foo>
  </xsl:template>
</xsl:stylesheet> 

gives

<?xml version="1.0" encoding="UTF-8"?>
<foo>    Gender: Male    </foo>

You are using HTML as the output? Then use non breaking space for whitespace.

查看更多
甜甜的少女心
4楼-- · 2019-04-21 01:33

If you want to output a text file you should specify an <xsl:output method="text"/> as a child of the <xsl:stylesheet> element.

When treating output as HTML the parser might pack your spaces, if HTML output with non-breaking spaces is what you want you can use the &#160; non-breaking space entity (note that &nbsp; might not work since it's not an XML entity, unless you declare it yourself).

查看更多
Summer. ? 凉城
5楼-- · 2019-04-21 01:46

You may need the to use...

<xsl:text xml:space="preserve">    Gender: Male    </xsl:text>
查看更多
一夜七次
6楼-- · 2019-04-21 01:51

Just use

  &#160;Gender: Male&#160; 

it represent whitespace in xsl like

 &nbsp;Gender:Male&nbsp; 

in html

查看更多
登录 后发表回答