我正在創建XSLT文件,並將XML文件中的一些數據顯示爲CSV。 我被困在一個特定的方面,因爲我無法找到許多類似xml結構的在線示例。在xslt中分組多個相同的節點內容
鑑於這種假設的XML:
<collection>
<book>
<author> author1name </author>
<author> author2name </author>
<title> booktitle </title>
</book>
<book>
<author> authorname </author>
<title> booktitle </title>
</book>
</collection>
而XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" >
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
author,title
<xsl:for-each select="//book">
<xsl:value-of select="concat
(author,',',title',','
')"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
其中給出的
author, title
author1name, booktitle
authorname, booktitle
注意的輸出,有包括在輸出沒有author2。這是數據的一大損失。 我試圖使用嵌套for循環來循環所有作者,但我已經打了太多的錯誤來計數。
有人建議可以產生的
author1name;author2name, booktitle
輸出爲一個書的方法? (兩位作者用分號分隔)
感謝您的幫助。