No, you can't affect the preceding-sibling(and any other) axis using xsl:sort instruction(an XSLT processor maintains internal tree of the source XML document, and when you use an axis, it looks in the tree independent of any sorting you specify). xsl:sort just guarantees that the current nodeset will be processed in the order you specified; you must rearrange the nodes to achieve the goal: copy all the "bar" elements into a variable, and then use your technique:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
<xsl:output method="text"/>
<xsl:template match="foo">
<xsl:variable name="bars">
<xsl:for-each select="bar">
<xsl:sort select="."/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="exsl:node-set($bars)/*">
previous siblings for node <xsl:value-of select="."/>:
<xsl:for-each select="current()/preceding-sibling::bar">
<xsl:value-of select="."/><xsl:text> </xsl:text>
</xsl:for-each>
<xsl:text>#10;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The XSLT processor you're using must support EXSLT's node-set extension function, or otherwise it must provide its own extension function to be able to convert tree fragment to nodeset.
Regards,
Armen