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

XSLT将分隔符从分号更改为逗号,并按字母顺序对值进行排序

XSLT将分隔符从分号更改为逗号,并按字母顺序对值进行排序,xslt,Xslt,如何将分隔符从分号改为逗号,并在XSLT中按字母顺序对值排序?请告知 现有标签 <component> <rate>T;P;C;X;R</rate> </component> <component> <rate>C,P,R,T,X</rate> </component> TPCX;R 预期标签 <component> <rate>T;P;C;X;

如何将分隔符从分号改为逗号,并在XSLT中按字母顺序对值排序?请告知

现有标签

<component>
    <rate>T;P;C;X;R</rate>
</component>
<component>
    <rate>C,P,R,T,X</rate>
</component>

TPCX;R
预期标签

<component>
    <rate>T;P;C;X;R</rate>
</component>
<component>
    <rate>C,P,R,T,X</rate>
</component>

C、 P,R,T,X

更改分隔符的部分很容易:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/component">
    <component>
      <rate>
        <xsl:value-of select="translate(rate, ';', ',')"/>
      </rate>
    </component>
  </xsl:template>
</xsl:stylesheet>


但是,对于排序部分,它更具挑战性…

如果您可以使用XSLT 3.0,那么您可以使用
tokenize()
string-join()
sort()

<xsl:template match="rate">
  <xsl:copy>
    <xsl:value-of select="string-join(sort(tokenize(normalize-space(),';')),',')"/>
  </xsl:copy>
</xsl:template>

XSLT1.0、2.0或3.0?谢谢@Daniel,Babelabout。。这很有帮助。不幸的是,我们使用的是XSLT 1.0,因此您能否建议如何在排序时完成此操作?@DJayE您使用的是哪个XSLT 1.0处理器?@michael.hor257k旧服务器处理XSLT并将其转换为其他系统的XML文件。因此,我们不得不接受XSLT1。0@DJayE-您知道旧服务器使用什么XSLT处理器吗?我想Michael是在问,这样我们就知道可能支持哪些扩展函数了。@DJayE Daniel Haley是对的。如果您不知道它是哪个处理器,请查找: