I'm creating and XSLT file to display some data from an XML file as CSV. I'm stuck on a particular aspect because I can't find many online examples with similar xml structure.
Given this hypothetical XML:
<collection>
<book>
<author> author1name </author>
<author> author2name </author>
<title> booktitle </title>
</book>
<book>
<author> authorname </author>
<title> booktitle </title>
</book>
</collection>
And the 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>
Which gives an output of
author, title
author1name, booktitle
authorname, booktitle
Note that there is no author2 included in the output. This is a big loss of data. I've tried to use a nested for loop to cycle through all authors but I've hit too many errors to count.
Can someone suggest a method to produce an output of
author1name;author2name, booktitle
for book one? (where the two authors are separated by semicolon)
Thanks for your help.