A
Andy Fish
Hi,
I just found this template in someone else's xslt (it's Microsoft's
"word2html" stylesheet to convert WordProcessingML to HTML)
<xsl:template match="WX:sect">
<xsl:variable name="thisSect" select="."/>
<div>
<xsl:for-each select="//WX:sect">
<xsl:if test=".=$thisSect">
<xsl:attribute name="class">Section<xsl:value-of
select="position()"/></xsl:attribute>
.....
It seems that the author is looping through all the WX:sect nodes looking
for the context node, in order to extract the position. However, I don't
understand the <xsl:if> test. According to the xpath spec:
"If both objects to be compared are node-sets, then the comparison will be
true if and only if there is a node in the first node-set and a node in the
second node-set such that the result of performing the comparison on the
string-values of the two nodes is true".
For this code to work, the "=" operator needs to compare two node sets to
see if they are pointing at the same object (like == in Java), which is a
very different thing. But the output looks correct.
Can anyone shed some light on this?
TIA
Andy
I just found this template in someone else's xslt (it's Microsoft's
"word2html" stylesheet to convert WordProcessingML to HTML)
<xsl:template match="WX:sect">
<xsl:variable name="thisSect" select="."/>
<div>
<xsl:for-each select="//WX:sect">
<xsl:if test=".=$thisSect">
<xsl:attribute name="class">Section<xsl:value-of
select="position()"/></xsl:attribute>
.....
It seems that the author is looping through all the WX:sect nodes looking
for the context node, in order to extract the position. However, I don't
understand the <xsl:if> test. According to the xpath spec:
"If both objects to be compared are node-sets, then the comparison will be
true if and only if there is a node in the first node-set and a node in the
second node-set such that the result of performing the comparison on the
string-values of the two nodes is true".
For this code to work, the "=" operator needs to compare two node sets to
see if they are pointing at the same object (like == in Java), which is a
very different thing. But the output looks correct.
Can anyone shed some light on this?
TIA
Andy