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或whit中对变量中的值进行排序_Xslt_Xpath - Fatal编程技术网

在xslt或whit中对变量中的值进行排序

在xslt或whit中对变量中的值进行排序,xslt,xpath,Xslt,Xpath,如何对包含逗号分隔字符串的变量中的值进行排序 如果在001a等的子字符串上分隔变量,则可以。 我的变量是一个由逗号分隔的值字符串,但由于我将更多文档中的字符串连接在一起,因此它们的顺序不正确。是这样的: 001a, 001b, 001d, 100a, 100c, 100d, 001c, 001f, 100b,... 我想得到这个: 001a, 001b, 001c, 001d, 100a, 001b, 100c, 100d, 001f,... 使用XSL 2.0: <?xml ver

如何对包含逗号分隔字符串的变量中的值进行排序

如果在
001a
等的子字符串上分隔变量,则可以。 我的变量是一个由逗号分隔的值字符串,但由于我将更多文档中的字符串连接在一起,因此它们的顺序不正确。是这样的:

001a, 001b, 001d, 100a, 100c, 100d, 001c, 001f, 100b,... 
我想得到这个:

001a, 001b, 001c, 001d, 100a, 001b, 100c, 100d, 001f,...
使用XSL 2.0:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">
    <xsl:variable name="unsorted" select="'001a, 001b, 001d, 100a, 100c, 100d, 001c, 001f, 100b'"/>
    <xsl:variable name="sorted">
        <xsl:for-each select="tokenize($unsorted, ', ')">
            <xsl:sort select="." />
            <xsl:choose>
                <xsl:when test="position()!=last()">
                    <xsl:value-of select="."/><xsl:text>, </xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="."/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>

    <xsl:template match="/">
        <unsorted><xsl:value-of select="$unsorted"/></unsorted>

        <sorted><xsl:value-of select="$sorted"/></sorted>
    </xsl:template>
</xsl:stylesheet>

, 
或者您可以参考(XSL 1.0解决方案)