[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: unparsed-text and nodes by position

Subject: Re: unparsed-text and nodes by position
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Fri, 25 Dec 2009 15:14:57 +0100
Re:  unparsed-text and nodes by position
Dear Brian,

There are two issues:

1. empty (or whitespace-only) elements
2. everything seems to be position()=1

ad 1.
This is because if you split '|a|b|c|' at '|', you will get five (!) elements, the first and last being empty. You should process the input so that your inner tokenizer encounters strings such as 'a|b|c'.

ad 2.
This is because in the for-each loop, the dynymic context is being set to every item in turn. So inside for-each, the current item is the only item in the dynymic context, and its position is always 1. http://www.w3.org/TR/xpath-functions/#func-position In these circumstances it often helps to store the sequence in a variable (you might use something like fn:index-of($line, .) inside for-each if you really want to check the position of the current element -- but this is only unambiguous if everybody has a unique name within a family).

Here's a solution:

 <xsl:template match="/">
     <xsl:if test="unparsed-text-available('test.txt', 'ISO-8859-1')">
       <xsl:variable name="datafile" select="unparsed-text('test.txt', 'ISO-8859-1')" as="xs:string"/>
       <xsl:for-each select="tokenize(normalize-space($datafile), '[\s*\r\n]+')">
           <xsl:variable name="line"
                       replace(., '^[|]Family[|](.+?)[|]?\s*$', '$1'),
             as="xs:string*" />
             <xsl:value-of select="$line[1]"/>
             <xsl:value-of select="$line[2]"/>
           <xsl:for-each select="$line[position() gt 2]">
               <xsl:value-of select="."/>


Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.