Convert XML having multiple for-each case to CSV

I guess the inner <xsl:for-each select="/TURFS/TURF"> should be <xsl:for-each select="TURFS/TURF">. And concat(AREANAME,',',DEAFAULT should be concat(AREANAME,',',DEFAULT.


I believe you could do simply:

XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="/root">
    <!-- header -->
    <xsl:text>TECHNICIANID,CUID,TURFS/TURF/0/AREANAME,TURFS/TURF/0/DEFAULT,TURFS/TURF/0/ALTERNATE,TURFS/TURF/1/AREANAME,TURFS/TURF/1/DEFAULT,TURFS/TURF/1/ALTERNATE&#10;</xsl:text>
    <!-- data -->
    <xsl:for-each select="row">
        <xsl:value-of select=".//*[not(*)]" separator=","/>
        <xsl:text>&#10;</xsl:text>  
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Demo: https://xsltfiddle.liberty-development.net/bF2MmXG/1


If you want to pick the values explicitly, then change:

<xsl:value-of select=".//*[not(*)]" separator=","/>

to:

<xsl:value-of select="TECHNICIANID, CUID, TURFS/TURF[1]/(AREANAME, DEFAULT, TALTERNATE), TURFS/TURF[2]/(AREANAME, DEFAULT, TALTERNATE)" separator=","/>