Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Preceding with partial string [Thread Next] Re: Preceding with partial stringTo: NULL Date: 6/6/2008 3:05:00 PM rnakawat@g... wrote: > <xsl:for-each select="./Row[Cell[@Name = 'Street' and not(@Value = > preceding::Cell[@Name= 'Street']/@Value) ]]"> > <xsl:for-each select="./Row[Cell[@Name = 'Address' and > not(substring-after(@Value, ' ') = substring- > after(preceding::Cell[@Name= 'Address']/@Value, ' ')) ]]"> > Can someone explain why that is happening and how I can fix it? The first comparison compares two node-sets (one with the single attribute @Value, one with all @Value attributes of preceding::Cell elements). The second comparison however compares the single @Value attribute to the string result of substring-after applied to the node-set of @Value attributes of preceding::Cell elements and that way you only compare to one preceding attribute, not to all. With XSLT 2.0 you could use <xsl:for-each select="./Row[Cell[@Name = 'Address' and not(substring-after(@Value, ' ') = preceding::Cell[@Name= 'Address']/@Value/substring-after(., ' ')) ]]"> to make sure you compare to a sequence and not a string value but that solution does not exist in XSLT 1.0. And XSLT 2.0 has other (easier) ways to identify distinct values, there is the function distinct-values http://www.w3.org/TR/xpath-functions/#func-distinct-values and there is xsl:for-each-group. With XSLT 1.0 you need to use Muenchian grouping: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="by-street" match="Row" use="substring-after(Cell[@Name = 'Address']/@Value, ' ')"/> <xsl:template match="Root"> <root> <xsl:for-each select="Row[generate-id() = generate-id(key('by-street', substring-after(Cell[@Name = 'Address']/@Value, ' '))[1])]"> <street> <xsl:value-of select="substring-after(Cell[@Name = 'Address']/@Value, ' ')"/> </street> </xsl:for-each> </root> </xsl:template> </xsl:stylesheet> -- Martin Honnen http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
