我有以下XML:
<?xml version="1.0" encoding="UTF-8"?>
<Report xmlns:fpml="http://www.fpml.org/FpML-5/confirmation" xmlns="http://www.eurexchange.com/EurexIRSFullInventoryReport" name="CB202 Full Inventory Report">
<reportNameGrp>
<CM>
<acctTypGrp name="A4">
<ProductType name="Swap">
<currTypCod value="EUR">
</currTypCod>
<currTypCod value="GBP">
</currTypCod>
</ProductType>
</acctTypGrp>
<acctTypGrp name="A8">
<ProductType name="Swap">
<currTypCod value="CHF">
</currTypCod>
<currTypCod value="EUR">
</currTypCod>
<currTypCod value="GBP">
</currTypCod>
</ProductType>
</acctTypGrp>
</CM>
</reportNameGrp>
</Report>
为此,我使用了这个 XSLT 转换(基于 https://stackoverflow.com/a/27458587/2564301):
<xsl:stylesheet version="1.0"
xmlns:fpml="http://www.fpml.org/FpML-5/confirmation" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:eur="http://www.eurexchange.com/EurexIRSFullInventoryReport">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/eur:Report">
<Eurexflows>
<xsl:apply-templates
select="eur:reportNameGrp/eur:CM/eur:acctTypGrp/eur:ProductType" />
</Eurexflows>
</xsl:template>
<xsl:template match="eur:ProductType">
<EurexMessageObject>
<name>
<xsl:value-of select="../@name" />
</name>
<ProductType>
<xsl:value-of select="@name" />
</ProductType>
<value>
<xsl:value-of select="eur:currTypCod/@value" />
</value>
</EurexMessageObject>
</xsl:template>
</xsl:stylesheet>
现在我希望我的输出 XML 是这样的:
<Eurexflows xmlns:eur="http://www.eurexchange.com/EurexIRSFullInventoryReport"
xmlns:fpml="http://www.fpml.org/FpML-5/confirmation">
<EurexMessageObject>
<name>A4</name>
<ProductType>Swap</ProductType>
<value>EUR,GBP</value>
</EurexMessageObject>
<EurexMessageObject>
<name>A8</name>
<ProductType>Swap</ProductType>
<value>CHF,EUR,GBP</value>
</EurexMessageObject>
</Eurexflows>
在 XSLT 中,我需要对value
标记进行哪些更改?
value-of
不适用于多个匹配元素:
。在 XSLT 1.0 中,
<xsl:value-of select="someNodeSet"/>
仅输出someNodeSet
中第一个节点的字符串值 (https://stackoverflow.com/a/6913772/2564301)
使用 <xsl:for-each>
而不是单个value-of
:
<value>
<xsl:for-each select="eur:currTypCod/@value">
<xsl:if test="position()>1">,</xsl:if>
<xsl:value-of select="." />
</xsl:for-each>
</value>