本文介绍了逗号分隔的字符串解析 XSLT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何循环遍历我在 XSLT 1.0 中作为参数传递的逗号分隔字符串?前-
How can I loop through a Comma separated string which I am passing as a parameter in XSLT 1.0?Ex-
<xsl:param name="UID">1,4,7,9</xsl:param>
我需要循环上述 UID 参数并从我的 XML 文件中的每个 UID 中收集节点
I need to loop the above UID parameter and collectd nodes from within each of the UID in my XML File
推荐答案
这是使用 .
Here is an XSLT 1.0 solution using the str-split-to-words
template of FXSL.
请注意,此模板允许拆分多个分隔符(作为单独的参数字符串传递),因此即使 1,4 7;9
也可以毫无问题地拆分使用此解决方案.
Note that this template allows to split on multiple delimiters (passed as a separate parameter string), so even 1,4 7;9
will be split without any problems using this solution.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ext="http://exslt.org/common"
>
<xsl:import href="strSplit-to-Words.xsl"/>
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:call-template name="str-split-to-words">
<xsl:with-param name="pStr" select="/"/>
<xsl:with-param name="pDelimiters"
select="', ;	 '"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
当此转换应用于以下 XML 文档时:
<x>1,4,7,9</x>
产生想要的、正确的结果:
<word>1</word>
<word>4</word>
<word>7</word>
<word>9</word>
这篇关于逗号分隔的字符串解析 XSLT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!