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_Xslt 2.0 - Fatal编程技术网

Xslt 仅带前导空格

Xslt 仅带前导空格,xslt,xslt-2.0,Xslt,Xslt 2.0,给定元素: <comments> comments go here </comments> 注释 到这里来 如何剥离多个前导空格字符。我不能使用规范化空间,因为我需要保留换行符等。XSLT 2.0正常。使用replace()函数: replace($input,'^ +','') 它只处理前导空格字符,直到第一个非空格字符。如果要删除第一个非空格之前的所有前导空格字符(即空格、nl、cr、tab),请使用: replace($input,'^\s+','')

给定元素:

 <comments>  comments
go here
</comments>
注释
到这里来
如何剥离多个前导空格字符。我不能使用规范化空间,因为我需要保留换行符等。XSLT 2.0正常。

使用
replace()
函数:

replace($input,'^ +','')
它只处理前导空格字符,直到第一个非空格字符。如果要删除第一个非空格之前的所有前导空格字符(即空格、nl、cr、tab),请使用:

replace($input,'^\s+','')
XPath1.0中的(也意味着XSLT1.0):

substring($input, 
          string-length(
                        substring-before($input, 
                                         substring(translate($input, ' ', ''), 
                                                   1,
                                                   1)
                                         )
                       ) +1
          )
包装在XSLT转换中

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

 <xsl:variable name="input"
   select="string(/*/text())"/>

 <xsl:template match="/">
   '<xsl:value-of select=
   "substring($input,
              string-length(
                            substring-before($input,
                            substring(translate($input, ' ', ''),
                                      1,
                                      1)
                                             )
                            ) +1
              )
   "/>'
 </xsl:template>
</xsl:stylesheet>
<t>    XXX   YYY Z</t>
   'XXX   YYY Z'

谢谢你的提醒。我想我应该读一下说明书,因为我直到上一篇文章才注意到。好问题(+1)。有关XPath 1.0单行程序解决方案,请参见我的答案。:)