[Home] [By Thread] [By Date] [Recent Entries]
Jitendra Kharche wrote:
Hi Jitendra, XSLT works with node trees, which you may view as something as a hierarchical array. An element on the same node level can be accessed using [] syntax, like in languages such as C and Java. And you can "loop" like in those languages using the for-each construct. But XSLT is not like those languages. XSLT is a declarative language and comes closer to Lisp than to imparative languages like C, Java, Ruby, VB etc. What comes close to your problem I think is this (XSLT 2.0): <xsl:variable name="csv-contents" > <!-- loop through the lines of the CSV file (replace unparsed-text function with your CSV string or text-node) --> <xsl:for-each select="tokenize(unparsed-text('some_csv_file.txt', 'UTF-8'), '\n|\r')"> <row> <!-- loop through the cells of the current line --> <xsl:for-each select="tokenize(., ';')" > <cell><xsl:value-of select="normalize-space(.)"/></cell> </xsl:for-each> </row> </xsl:for-each> </xsl:variable> You can now use this variable $csv-contents as a tree anywhere you like (it's your "array" of nodes, pass it on to your "separate template", included or otherwise). In XSLT 1.0 you cannot do such a thing (you cannot built a temporary tree and use it again and you cannot use tokenize). But as Mukul Gandhi pointed out, there are solutions around. I suggest chapter 2.9 of the XSLT Cookbook (O'Reilly), it worked for me. Cheers! Abel
|

Cart



