我有以下 XML 文档:
<?xml version="1.0" encoding="UTF-8"?>
<cars>
<car>
<entrydata columnnumber="4" name="Colour">
<text>Red</text>
</entrydata>
</car>
<car>
<entrydata columnnumber="4" name="Colour">
<textlist>
<text>Yellow</text>
<text>Blue</text>
</textlist>
</entrydata>
</car>
</cars>
以及以下 XSLT 样式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com: xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<records>
<xsl:apply-templates select="//cars"/>
</records>
</xsl:template>
<!--Top level template -->
<xsl:template match="cars">
<!-- Loop through each document (viewentry) and apply create the rows for each one-->
<xsl:for-each select="car">
<record>
<xsl:attribute name="Colour">
<xsl:value-of select="entrydata[@name='Colour']"/>
</xsl:attribute>
</record>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
这会产生以下输出:
<?xml version="1.0" encoding="UTF-8"?>
<records>
<record Colour="Red"/>
<record Colour="YellowBlue"/>
</records>
我将如何修改 XSLT 文件以使输出变为(注意逗号分隔<textlist>
):
<?xml version="1.0" encoding="UTF-8"?>
<records>
<record Colour="Red"/>
<record Colour="Yellow, Blue"/>
</records>