html - xslt 允许在 concat 和 normalize-space 中使用参数

标签 html xml xslt xpath xquery

我正在查看一些代码,我看到了这个:

<xsl:variable name="newlist" select="concat(normalize-space($list), ' ')" />

我只是想知道这个信息,我可以肯定地说 $list 是一个 string 并且 normalize-space($list) 肯定会返回给我一个 string 和行 concat(normalize-space($list), ' ') 肯定会返回一个 string (最后一个该字符串的字符是空格?)

最佳答案

$list 可以是字符串、数字、节点集,任何东西。结果将是一个字符串。是的,最后一个字符将是一个空格。

例如:

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

    <xsl:output omit-xml-declaration="yes"/>

    <xsl:template match="/">
        <xsl:variable name="node">
            <node>
                <subnode>string</subnode>
                <subnode>otherstring</subnode>
            </node>
        </xsl:variable>
    <xsl:variable name="string" select="concat($node,' ')"/>
    <xsl:value-of select="string-length($string)"/>
    <xsl:value-of select="substring-before($string,' ')"/>
    </xsl:template>

</xsl:stylesheet>

返回

18stringotherstring

关于html - xslt 允许在 concat 和 normalize-space 中使用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6276481/

相关文章:

Javascript 数组在数组项之前打印未定义

需要 JavaScript 来填充内容和页脚之间的剩余高度空间

Android - 使用库项目时的通用样式资源?

xslt - 使用 xslt 添加具有静态值的属性

xml - 合并2个XML文件并修改属性值

javascript - 创建动态表单

javascript - 在红色和绿色之间切换标题的颜色

xml - 这对于 xpath 来说是不可能的吗?

java - Bitcask 可以用于简单和高性能的文件存储吗?

xslt - 使用 XSLT key() 函数根据单独元素中的两个属性查找节点