Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Preceding with partial string

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent