[edit] post updated with revised XML and desired output as detailed in Vincent Biragnet's answer and comments.
I'm trying to put together some code to convert XML data into a text based meta file. I'm having no luck getting it to spit out desired output and am currently kinda stuck, so any help would be appreciated.
XSLT 1.0 does not make tokenizing easy and that's where I got stuck: I would like to treat @syn as a CSV string and break it apart when needed.
I'm working with the following XML data (please note that all nodes, except for the <Meta> node, in this XML file can have any name.)
<Meta>
<Subject>
<People>
<Jane_Doe syn="janie, jd" />
<John_Doe/>
</People>
<Object>
<Table>
<Leg/>
</Table>
<Chair syn="seat" />
</Object>
</Subject>
<Test1>
<Test2 syn="testy"/>
<Test3>
<Test4/>
</Test3>
</Test1>
</Meta>
This XML needs to be converted so the output looks this:
[Subject]
[People]
Jane_Doe
{janie}
{jd}
John_Doe
[Object]
[Table]
Leg
Chair
{seat}
[Test1]
Test2
{testy}
[Test3]
Test4
My current XSL:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" indent="yes"/>
<xsl:template match="/Meta"><xsl:apply-templates/></xsl:template>
<xsl:template match="child::*"><xsl:call-template name="master"/><xsl:apply-templates/></xsl:template>
<xsl:template name="master">
<xsl:choose>
<xsl:when test="count(child::*) = 0">
<xsl:value-of select="local-name()"/>
<xsl:apply-templates select="@syn"/>
</xsl:when>
<xsl:otherwise>
[<xsl:value-of select="local-name()"/>]
<xsl:apply-templates select="@syn"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tokenize" match="@syn">
<xsl:param name="text" select="."/>
<xsl:param name="separator" select="','"/>
<xsl:value-of select="$text"/>
<xsl:choose>
<xsl:when test="not(contains($text, $separator))">
{<xsl:value-of select="normalize-space($text)"/>}
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(substring-before($text, $separator))"/>
<xsl:call-template name="tokenize">
{<xsl:with-param name="text" select="substring-after($text, $separator)"/>}
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>