Sorry the wrong pasting. I rewrite the earlier reply.
Thanks for your comment, Oleg.
After your comment, I noticed the problem or difference comes only when I do
sum().
$p/. | preceding-sibling::* / @a1
parent::*/*[count(preceding-sibling::*) <= $p/preceding-sibling::*)]/@a1
Two xpaths may have same result when we select or do count(). However when I
do sum(),
sum($p/. | preceding-sibling::* / @a1)
sum($p/parent::*/*[count(preceding-sibling::*) <=
$p/preceding-sibling::*)]/@a1)
The results are different. How can I use the first xpath when I do sum()?
Help me. Here is an example xml+xslt.
<a>
<b a1='1'/>
<c a1='2'/>
<d/>
</a>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method='xml'
indent='yes' omit-xml-declaration='yes'/>
<xsl:template match="c">
<xsl:call-template name='t'>
<xsl:with-param name='p' select='.'/>
</xsl:call-template>
</xsl:template>
<xsl:template name='t'>
<xsl:param name='p'/>
<xsl:copy-of select='$p'/>
<c1>
<!--xsl:value-of select="
sum($p/. | preceding-sibling::* / @a1)"/-->
<xsl:value-of select="
sum($p/parent::*/*[count(preceding-sibling::*) <=
count($p/preceding-sibling::*)]/@a1)"/>
</c1>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Post by HanThanks for your commend, Oleg.
After your comment, I noticed the problem or difference comes only when I do
sum().
parent::*/*[count(preceding-sibling::*) <=
Two xpaths may have same result when we select or do count(). However when I
do sum(),
sum($p/parent::*/*[count(preceding-sibling::*) <=
The results are different. How can I use the first xpath when I do sum()?
Help me. Here is an example xml+xslt.
<a>
<b a1='1'/>
<c a1='2'/>
<d/>
</a>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method='xml'
indent='yes' omit-xml-declaration='yes'/>
<xsl:template match="c">
<xsl:call-template name='t'>
<xsl:with-param name='p' select='.'/>
</xsl:call-template>
</xsl:template>
<xsl:template name='t'>
<xsl:param name='p'/>
<xsl:copy-of select='$p'/>
<c1>
<!--xsl:value-of select="
<xsl:value-of select="
sum($p/parent::*/*[count(preceding-sibling::*) <=
</c1>
</xsl:template>
<xsl:copy>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Post by Oleg Tkachenko [MVP]Post by HanWe know ancestor-or-self, descendant-or-self. But what if we want
preceding-sibling-or-self? No such thing. "|" doesn't work as I
expect.
Post by Hane.g.
Post by Oleg Tkachenko [MVP]Post by Han.|preceding-sibling::*[blahblah]
Should work. Why do you think it doesn't work?
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com