我有下面的XML文檔:XSLT逗號元素脫離
<?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>
這是一個起點:http://www.xsltcake.com/slices/t4nxk9/2 – joshcomley 2012-07-10 09:52:59