I have a blob of text with delimiters that I'd like to format into an HTML table using XSLT 2.0 (saxon). The text blob (param myTable in this example) contains records separated with |c|. After the 6th record it should become a new row. There's also a |r| delimiter I could use.
So I thought I would use tokenize on the column delimiter to insert the html column tags and then use for-each-group to insert the html row tags. However, having only written fairly simple XSLT until this point, I'm struggling on proper usage.
When using the XML below, I get an error saying that for-each-group has to be of type node(), and not xs:string, which is what tokenize is producing.
I suspect I'm approaching this in a fundamentally wrong way, but I'm stuck with using XSLT and this incoming blob. Any advice appreciated!
<xsl:param name="myTable" />
<xsl:param name="tdSeparator" select="'\|c\|'"/>
<xsl:param name="trSeparator" select="'\|r\|'"/>
<xsl:template name="makeTable">
<xsl:for-each-group select="fn:tokenize($myTable,$tdSeparator)" group-ending-with="*[position() mod 6 = 0]">
<tr>
<xsl:for-each select="current-group()">
<td><xsl:copy-of select="current()" /></td>
</xsl:for-each>
</tr>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="xvar:metric1" xmlns:xvar="http://test.com/xvar/example">
<root>
<html>
<HEAD>
<META content="text/html; charset=us-ascii" />
</HEAD>
<body>
<p><strong>EMAIL HEADER</strong></p>
<p><strong>Key0: </strong> <xsl:value-of select="xvar:key0" /></p>
<p><strong>Value1: </strong> <xsl:value-of select="xvar:value1" /></p>
etc...
<table>
<xsl:call-template name="makeTable" />
</table>