Subject: [xsl] Odd bug? in msxml3 xslt implementation From: Unico Hommes <Unico@xxxxxxxx> Date: Tue, 27 Mar 2001 13:01:09 +0200 |
Hi all, I have found a really weird behavior in microsofts xslt processor. Consider the following xml document: <itemlist> <item> <name>item name</name> </item> <item> <name>item name</name> </item> <item> <name>item name</name> </item> <item> <name>different item name</name> </item> </itemlist> ... and the following xsl transformation document for it: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/itemlist"> <p> <xsl:call-template name="itemtemplate"> <xsl:with-param name="name">none</xsl:param> <xsl:with-param name="$position">1</xsl:position> </xsl:call-template> </p> </xsl:template> <xsl:template name="itemtemplate"> <xsl:param name="name" /> <xsl:param name="position" /> <xsl:choose> <xsl:when test="item[$position]/name != $name"> <xsl:value-of select="item[$position]/name" /> != <xsl:value-of select="$name" /><br /> </xsl:when> <xsl:otherwise> <xsl:value-of select="item[$position]/name" /> == <xsl:value-of select="$name" /><br /> </xsl:otherwise> </xsl:choose> <xsl:if test="$position != count(product)"> <xsl:call-template name="itemtemplate"> <xsl:with-param name="name" select="item[$position]/name" /> <xsl:with-param name="position" select="$position + 1" /> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> ... wich after processing produces the following: <?xml version="1.0" encoding="UTF-16"?> <p> item name != none<br /> item name != item name<br /> item name == item name<br /> different item name != item name<br /> </p> ... to explain a little further what I am trying to do in my xslt ... ... I want to output only those item names that are not equal to the previous item names as long as there are items to check. So : <xsl:if test="$position != count(product)"> I recursively call the named template 'itemtemplate' : <xsl:call-template name="itemtemplate"> with the current item name : <xsl:with-param name="name" select="item[$position]/name" /> and the next position : <xsl:with-param name="position" select="$position + 1" /> Now taking a look at the output it is obvious that : item name != item name is just not expected. ... But check out what happens if I reverse the test proposition, that is to say, when instead of: <xsl:choose> <xsl:when test="item[$position]/name != $name"> <xsl:value-of select="item[$position]/name" /> != <xsl:value-of select="$name" /><br /> </xsl:when> <xsl:otherwise> <xsl:value-of select="item[$position]/name" /> == <xsl:value-of select="$name" /><br /> </xsl:otherwise> </xsl:choose> ... I write: <xsl:choose> <xsl:when test="item[$position]/name == $name"> <xsl:value-of select="item[$position]/name" /> == <xsl:value-of select="$name" /><br /> </xsl:when> <xsl:otherwise> <xsl:value-of select="item[$position]/name" /> != <xsl:value-of select="$name" /><br /> </xsl:otherwise> </xsl:choose> ... (substituting the inequality check into an equality check) ... in this case the output is : <?xml version="1.0" encoding="UTF-16"?> <p> item name != none<br /> item name == item name<br /> item name == item name<br /> different item name != item name<br /> </p> ... wich is what could be expected. I found this a particularly weird bug. Now I have an additional question for those that have followed me thus far. Suppose the items within my xml source document did not occur in a specific order but I wanted to output only unique item names. So for instance my xml document looked like so : <itemlist> <item> <name>item name</name> </item> <item> <name>different item name</name> </item> <item> <name>item name</name> </item> </itemlist> ... but I wanted to output only unique item names as in : <p> item name<br /> different item name<br /> </p> ... I wouldn't be able to use the above xslt since it only checks for equality to the previous item name, unless I found a way to sort the items by item name in wich case I cannot use a the named template strategy I guess. Does anybody have a solution to this problem, is there perhaps an xpath statement that would allow me to filter down my node set of <item>s to only those that have unique item names, in wich case I could use iteration ? Regards, Unico Hommes XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] <A> with parameters, Peter . FLYNN | Thread | RE: [xsl] Odd bug? in msxml3 xslt i, Michael Kay |
Re: RE: [xsl] element-available() q, Carmelo Montanez | Date | RE: [xsl] <A> with parameters, Lee Goddard |
Month |