开发者

xslt allowed arguments in concat and normalize-space

开发者 https://www.devze.com 2023-03-11 00:26 出处:网络
I was looking through some code and i saw this: <xsl:variable name=\"newlist\" select=\"concat(normalize-space($开发者_Python百科list), \' \')\" />

I was looking through some code and i saw this:

<xsl:variable name="newlist" select="concat(normalize-space($开发者_Python百科list), ' ')" />

I'm just wondering with just this info, can i safely say for sure that $list is a string and normalize-space($list) will definitely return me a string and the line concat(normalize-space($list), ' ') will definitely return me a string (and the last character of that string is a space?)


$list could be a string, a number, a node set, anything. The result will be a string. And yes, the last character will be a space.

For instance:

<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>

returns

18stringotherstring


I think you can safely assume this will return a string but you can't say for sure that $list is a string as normalize-space will attempt to convert to a string first. eg.

 <xsl:value-of select="concat(normalize-space(13), ' ')"/>

Will work.

More info on concat and normalize-space.

Also note that this could fail if $list is set incorrectly, such as

<xsl:variable name="list" select="12 34" />

So you can never really safely assume it will work without seeing the rest of the code.

0

精彩评论

暂无评论...
验证码 换一张
取 消