我需要使用“Name”提取客户名称,并通过删除重复的名称将其保存在变量中,如下所示。输入是任何虚拟xml
像响应变量应该只有这个
<customer name="Name">John; Kevin; Leon; Adam</customer>
使用了这个样式表
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="/">
<xsl:variable name="request">
<customers>
<customer name="Address">1 Doe Place</customer>
<customer name="State">OH</customer>
<customer name="Name">John</customer>
<customer name="Name">Kevin</customer>
<customer name="Name">Leon</customer>
<customer name="Name">Adam</customer>
<customer name="Name">Leon</customer>
<customer name="Name">Adam</customer>
<customer name="Name">John</customer>
<customer name="city">Columbus</customer>
</customers>
</xsl:variable>
<xsl:variable name="response" >
<xsl:for-each select="$request/customers/customer[@name = 'Name']">
<xsl:copy-of select="./text()"/>
<xsl:if test="position()!=last()">; </xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:copy-of select="$response"/>
</xsl:template>
</xsl:stylesheet>
这会生成
<customer name="Name">John; Kevin; Leon; Adam; Leon; Adam; John</customer>
但未删除重复的名称