There's certainly many ways how one can vary this, with field names
being used as tags rather
than attribute values, etc.
Also, it's easy to extend this to a wider range of formats, i.e., DSV,
by adding another
parameter and a dynamically constructed split pattern although being able to use
pattern metacharacters as a field delimiter may require additional precautions.
(My "test" data file uses semicolons as delimiters.)
<xsl:param name="fieldDel">,</xsl:param>
<xsl:variable name="p1">(("[^"]*")+|[^</xsl:variable>
<xsl:variable name="splitPattern" select="concat($p1, $fieldDel,
']*)', $fieldDel)" />
<xsl:function name="fn:getTokens" as="xs:string+">
<xsl:param name="str" as="xs:string" />
<xsl:analyze-string select="concat($str, $fieldDel)"
regex='{$splitPattern}'>
Thanks for this instructive example!
-W
On Wed, Feb 3, 2010 at 9:23 AM, Andrew Welch
<andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> wrote:
Also, but purely as a matter of taste and case, since all cell values are
strings, I would tend to use attributes, replacing
<elem name="{.}">
<xsl:value-of select="$lineItems[$pos]" />
</elem>
with
<xsl:attribute name="{.}" select="$lineItems[$pos]"/>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--