2017-06-19 103 views

回答

1

与改变分隔符的部分很容易:

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

但是,对于排序的一部分,它是多一点cha llenging ...

0

如果你可以使用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> 

如果你可以使用XSLT 2.0,您可以使用tokenize()string-join(),但你“将不得不使用xsl:sort(或xsl:perform-sort)来进行排序...

<xsl:template match="rate"> 
    <xsl:variable name="rates" as="item()*"> 
    <xsl:for-each select="tokenize(normalize-space(),';')"> 
     <xsl:sort data-type="text"/> 
     <xsl:value-of select="."/> 
    </xsl:for-each> 
    </xsl:variable> 
    <xsl:copy> 
    <xsl:value-of select="string-join($rates,',')"/> 
    </xsl:copy> 
</xsl:template> 
+0

谢谢@丹尼尔,Babelabout ..这有助于。不幸的是,我们使用XSLT 1.0,所以你可以请教如何在排序时完成这个工作? –

+0

@DJayE您正在使用哪种XSLT 1.0处理器? –

+0

@ michael.hor257k传统服务器处理XSLT并将其转换为其他系统的XML文件。所以不得不忍受XSLT 1.0 –