Don’t forget to include the xmlns:str="http://exslt.org/strings" namespace declaration and to include it also in exclude-result-prefixes so the str namespace does not appear in the target document.
Transformation
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:AS="http://schema.advantages.cz/AsapFunctions"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:str="http://exslt.org/strings"
exclude-result-prefixes="AS date str">
<xsl:template match="ROOT">
<ROOT>
<xsl:apply-templates select="WorkQueueEntry"/>
</ROOT>
</xsl:template>
<xsl:template match="WorkQueueEntry">
<!-- We split the source text into lines in this case by CR LF -->
<xsl:variable name="lines" select="str:split(Data, '
')"/>
<!-- Now we process each line -->
<xsl:for-each select="$lines">
<!-- We split the line into fields in this case by comma -->
<xsl:variable name="fields" select="str:split(., ',')"/>
<!-- Now we can process each field -->
<TargetEntity
field1="{$fields[1]}"
field2="{$fields[2]}"
field3="{$fields[3]}"
/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I agree. But what if you have different data input source file, where numbers are without quotation marks and strings are closed inside quotation marks. Then comes very nice situation, that inside quotation markes can appear COMMA. It only complicates it, of course.
Then I suggest using the following transformation.
Don’t forget to include the xmlns:regex="http://exslt.org/regular-expressions" namespace declaration and to include it also in exclude-result-prefixes so the regex namespace does not appear in the target document and you can use regular expression.
Transformation
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:AS="http://schema.advantages.cz/AsapFunctions"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:str="http://exslt.org/strings"
xmlns:regex="http://exslt.org/regular-expressions"
exclude-result-prefixes="AS date str regex">
<xsl:template match="ROOT">
<ROOT>
<xsl:apply-templates select="WorkQueueEntry"/>
</ROOT>
</xsl:template>
<xsl:template match="WorkQueueEntry">
<!-- We split the source text into lines in this case by CR LF -->
<xsl:variable name="lines" select="str:split(Data,'
')"/>
<!-- Now we process each line -->
<xsl:for-each select="$lines">
<!-- We split the line into Fld/row in this case by comma and replace all commas inside quotation marks for "_"-->
<xsl:variable name="fields" select="str:split(regex:replace(.,',(?=[^"]*"(?:[^"\r\n]*"[^"]*")[^"\r\n]*$)','ig','_'),',')"/>
<xsl:variable name="fldClr">
<xsl:for-each select="$fields">
<row>
<xsl:value-of select="str:replace(.,'"','')" />
</row>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="Fld" select="AS:NodeSet($fldClr)" />
<!-- now the result NodeSet can be accessed and processed -->
<TargetEntity>
<xsl:for-each select="$Fld/row">
<xsl:attribute name="concat('field',position())">
<xsl:value-of select="current()" />
</xsl:attribute>
</xsl:for-each>
</TargetEntity>
</xls:for-each>
</xsl:template>
</xsl:stylesheet>