我有一个具有以下结构的xml:
<FlightDetails>
<CouponNumber>1</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
<CouponNumber>2</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
<CouponNumber>3</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
使用的xslt是:
<FlightDetails>
<xsl:for-each select="FlightDetails/CouponNumber">
<CouponNumber>
<xsl:value-of select="." />
</CouponNumber>
</xsl:for-each>
<xsl:for-each select="FlightDetails/ServiceClass">
<ServiceClass>
<xsl:value-of select="." />
</ServiceClass>
</xsl:for-each>
</FlightDetails>
使用xslt将xml转换为输出xml显示:
<FlightDetails>
<CouponNumber>1</CouponNumber>
<CouponNumber>2</CouponNumber>
<CouponNumber>3</CouponNumber>
<ServiceClass>Y</ServiceClass>
<ServiceClass>Y</ServiceClass>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
但是,所需的输出xml应如下所示:
<FlightDetails>
<CouponNumber>1</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
<CouponNumber>2</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
<CouponNumber>3</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
如何修改XSLT以实现上述输出xml结构?
答案 0 :(得分:0)
你可以试试,
<强> XSL:强>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output indent="yes" />
<xsl:template match="/">
<xsl:copy-of select="//FlightDetails"/>
</xsl:template>
</xsl:stylesheet>
<强>输出:强>
<?xml version="1.0" encoding="UTF-8"?>
<FlightDetails>
<CouponNumber>1</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
<CouponNumber>2</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>
<FlightDetails>
<CouponNumber>3</CouponNumber>
<ServiceClass>Y</ServiceClass>
</FlightDetails>