如何在XSLT中选择和分隔逗号值
我的XML:如何在XSLT中选择和分隔逗号值,xslt,Xslt,我的XML: 36.113,-114.925 我需要一个XSLT,用于将上述XML转换为以下XML格式: <geoCode>36.113,-114.925</geoCode> 36.113 -114.925 您可以在模板中使用以下代码: <geoCode> <lati>36.113</lati> <longi>-114.925</longi> </geoCode> 注意:此
36.113,-114.925
我需要一个XSLT,用于将上述XML转换为以下XML格式:
<geoCode>36.113,-114.925</geoCode>
36.113
-114.925
您可以在模板中使用以下代码:
<geoCode>
<lati>36.113</lati>
<longi>-114.925</longi>
</geoCode>
注意:此解决方案使用XSLT2.0。对于XSLT1.0,可以使用string-before()
和string-after()
函数。
<xsl:template match="...">
<xsl:variable name="geo-code-split" select="tokenize(geoCode, ',')" />
<geoCode>
<lati><xsl:value-of select="$geo-code-split[1]" /></lati>
<longi><xsl:value-of select="$geo-code-split[2]" /></longi>
</geoCode>
</xsl:template>
这是前面的子字符串和后面的子字符串。这很简单:使用
substring-before()
和substring-after()
。您好,如果它们对您有效,请确认答案好吗?谢谢
<geoCode>
<lati>
<xsl:value-of select="substring-before(geoCode,',')"/>
</lati>
<longi>
<xsl:value-of select="substring-after(geoCode,',')"/>
</longi>
</geoCode>