我的源代码如下。我有具有不同值的相似数据元素。在下面的示例中,我有 3 个电话号码,我希望将所有电话号码都放在带有分隔符 (;) 的单行中,我使用了连接函数,但没有用
<?xml version="1.0" encoding="UTF-8"?>
<report_entry>
<report_data>
<Phone_Numbers_-_Home Descriptor="+44 (233) 45666">
<ID type="WID">16001e91f6ba1ewa583d2eafc901baa6</ID>
</Phone_Numbers_-_Home>
<Phone_Numbers_-_Home Descriptor="+44 (234) 56777">
<ID type="WID">16001ewsf6ba108a584e5d776077bbe3</ID>
</Phone_Numbers_-_Home>
<Phone_Numbers_-_Home Descriptor="+44 (123) 23450987">
<ID type="WID">16001e91f6ba1b8a582ab3e49446b92c</ID>
</Phone_Numbers_-_Home>
</report_data>
预期结果如下。我需要 ”;”黑白数据值
+44 (233) 45666 +44;(234) 56777;+44 (123) 23450987
我正在使用下面的代码,其中符号(;)出现在不需要的字符串末尾。我需要黑白电话值,但在最后一个值末尾不需要
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="2.0">
<xsl:output method="text" omit-xml-declaration="yes"></xsl:output>
<xsl:template match="/report_entry/report_data">
<xsl:value-of select="Phone_Numbers_-_Home/@Descriptor"/> <xsl:value-of select="';'"/>
</xsl:template>
最佳答案
应该很容易找到一种方法来分离 xsl:value-of select="Phone_Numbers_-_Home/@Descriptor"
选择的项目只需查看规范 https://www.w3.org/TR/xslt-30/#element-value-of在那里你找到一个名为 separator
的属性所以<xsl:value-of select="Phone_Numbers_-_Home/@Descriptor" separator=";"/>
这就是您所需要的。
关于xslt - 如何在 XSLT 中使用符号 (;) 分隔相似的数据元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50926009/