XSL 1.0: Loop through seperated values



I have the following XML:



<RESULTS>
<SEARCHRESULT RECORDS="54">
<ROW ROWNUM="1" PKField="COUNTER">
<COLUMN COLNUM="1" NAME="COUNTER" DATATYPE="number">1243</COLUMN>
<COLUMN COLNUM="2" NAME="KEY" DATATYPE="number">176</COLUMN>
<COLUMN COLNUM="3" NAME="NAME" DATATYPE="string">John Smith;Jane Doe;Alan Rickman</COLUMN>
<COLUMN COLNUM="4" NAME="TITLE" DATATYPE="string">Secretary;Partner;Director</COLUMN>
<COLUMN COLNUM="5" NAME="FROM_DATE" DATATYPE="date">21/04/2001;07/09/2002;27/05/2003</COLUMN>
<COLUMN COLNUM="6" NAME="TO_DATE" DATATYPE="date">12/01/2006;14/01/2003;06/03/2006</COLUMN>
<COLUMN COLNUM="7" NAME="DIVISION" DATATYPE="string">Retail</COLUMN>
</ROW>
</SEARCHRESULT>


I'm creating a XSLT file to transform it, currently it comes out like this:



KEY||NAME||TITLE||FROM_DATE||TO_DATE||DIVISION176||John Smith;
Jane Doe;
Alan Rickman||Secretary;
Partner;
Director||21/04/2001;
07/09/2002;
27/05/2003||12/01/2006;
14/01/2003;
06/03/2006||Retail


But I'm trying to make it come out like so:



KEY||NAME||TITLE||FROM_DATE||TO_DATE||DIVISION
176||John Smith||Secretary||21/04/2001||12/01/2006||Retail
176||Jane Doe||Partner||07/09/2002||14/01/2003||Retail
176||Alan Rickman||Director||27/05/2003||06/03/2006||Retail


I'm currently trying to use the following method:



<xsl:template name="loopOnSeperator">
<xsl:param name="String"/>
<xsl:param name="Counter" select="0" />
<xsl:variable name="sa" select="substring-after($String, $seperator)" />
<xsl:choose>
<xsl:when test="$sa != '' or contains($String, $seperator)">
<xsl:call-template name="loopOnSeperator">
<xsl:with-param name="String" select="$sa" />
<xsl:with-param name="Counter" select="$Counter + 1" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$String" />
</xsl:otherwise>
</xsl:choose>


But I am having difficulty especially with the KEY & DIVISION fields.


Any help would be greatly appreciated, thank you very much for your time.


No comments:

Post a Comment