Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除XSLT中引号内的空白_Xslt_Whitespace - Fatal编程技术网

删除XSLT中引号内的空白

删除XSLT中引号内的空白,xslt,whitespace,Xslt,Whitespace,我正在尝试从XML格式化一个表。假设我在XML中有这一行 <country>Dominican Republic</country> 多米尼加共和国 我想让我的桌子看起来像这样 <td class="country DominicanRepublic">Dominican Republic</td> 多米尼加共和国 我试过这个: <td class="country {country}"><xsl:value-of sel

我正在尝试从XML格式化一个表。假设我在XML中有这一行

<country>Dominican Republic</country>
多米尼加共和国 我想让我的桌子看起来像这样

<td class="country DominicanRepublic">Dominican Republic</td>
多米尼加共和国 我试过这个:

<td class="country {country}"><xsl:value-of select="country"/></td>

那么这个,

<xsl:element name="td">
 <xsl:attribute name="class">
  <xsl:text>country </xsl:text>
  <xsl:value-of select="normalize-space(country)"/>
 </xsl:attribute>
<xsl:value-of select="country"/>
</xsl:element>

国家
normalize-space()
不会删除名称两部分之间的空格,我不能使用
,因为在表格单元格中显示名称时需要空格


如何从类中的值中去除空格,而不是从单元格中的文本中去除空格?

您需要递归地用空格分割字符串,请查看此主题:

或者您可以尝试此替换函数实现:

使用函数将空格“”替换为空“”:


谢谢你,真管用!我还在学习XSL,所以感谢您的帮助:)实际上XML是另一个站点的提要,文本前面有空白。translate函数不会删除这个,有什么解决方案吗?我不知道如何堆叠函数,比如在转换后在国家/地区使用normalize。如果使用translate删除空格,则应该对所有空格都这样做。您确定它不是制表符、回车符或其他空白吗?您可以使用
normalize-space()
并将结果发送到
translate()
。我将用一个例子更新答案。那太完美了!再次感谢!
<xsl:element name="td">
    <xsl:attribute name="class">
        <xsl:text>country </xsl:text>
        <xsl:value-of select="translate(country,' ','')"/>
        </xsl:attribute>
    <xsl:value-of select="country"/>
</xsl:element>
<xsl:element name="td">
   <xsl:attribute name="class">
    <xsl:text>country </xsl:text>
    <xsl:value-of select="translate(normalize-space(country),' ','')"/>
    </xsl:attribute>
    <xsl:value-of select="normalize-space(country)"/>
</xsl:element>