在Excel中打开文件时,用XSL创build的空html列太宽
我正在创build一个报告,通过使用XSL将XML文件转换为HTML文件。 在某些情况下,我有一个总是空的列。 我的问题是,无论我设置这个列有多狭窄,它总是太宽(通常,当有一些文本是一个或两个字母,在这种情况下,列将是宽,以容纳最大的string,这是3比空时窄4倍)。 当我没有数据时,有没有办法让这个列变得非常窄? 下面是创buildHTML文件的XSL代码的一部分(将空值replace为“用空白元素replace”的代码)。 对于宽度属性,我尝试了不同的值,无论我放什么值,当列是空的列的宽度是相同的(在Excel中打开时太宽):“FONT-WEIGHT:粗体
<xsl:choose> **<!-- replace empty element with --> **<xsl:when test="string-length()= 0"> <xsl:attribute name="width">20px</xsl:attribute> <xsl:text disable-output-escaping="yes">&</xsl:text> <xsl:text>nbsp;</xsl:text>** </xsl:when>** <xsl:when test="contains(name(.), 'Location')"> <xsl:attribute name="align">left</xsl:attribute> <xsl:attribute name="colspan">2</xsl:attribute> <xsl:apply-templates/> </xsl:when> <xsl:otherwise> <xsl:attribute name="align">left</xsl:attribute> <xsl:apply-templates/> </xsl:otherwise> </xsl:choose> </td> </xsl:for-each> </tr> </xsl:for-each>
谢谢。
除非在这些元素上使用xsl:strip-space
,否则string-length()
也会计算空白。
尝试改变你的testing:
test="string-length(normalize-space())=0"
您也可以将其更改为:
test="not(boolean(normalize-space()))"
我认为这更容易理解。
您也可以使用十进制(或hex)参考为您的非rest空间(  
); 这将消除对2 xsl:text
和disable-output-escaping
。
你也可以使用零宽度空间: ​
。
以下是我将使它看起来像一个例子:
<xsl:when test="not(boolean(normalize-space()))"> <xsl:text>​</xsl:text> </xsl:when>