Project

Profile

Help

xslt ancestor axis question

Added by Anonymous over 17 years ago

Legacy ID: #4240490 Legacy Poster: snenkov_ (snenkov_)

Hi All, not very clear to me - should ancestor::* return nodes in document order or not? what is the correct output? <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes"/> <xsl:template match="/"> <out> <xsl:for-each select="//center"> <xsl:apply-templates select="ancestor::"/> </xsl:for-each> </out> </xsl:template> <xsl:template match=""> <xsl:value-of select="name(.)"/><xsl:text> </xsl:text> </xsl:template> </xsl:stylesheet> -------------------- <?xml version="1.0"?> <far-north> <north> <near-north> <far-west/> <west/> <near-west/> <center> <near-south> <south> <far-south/> </south> </near-south> </center> <near-east/> <east/> <far-east/> </near-north> </north> </far-north> ------------------ this? <out> near-north north far-north </out> ---------- or this? <out> far-north north near-north </out> Thanks Stefan


Replies (1)

RE: xslt ancestor axis question - Added by Anonymous over 17 years ago

Legacy ID: #4240811 Legacy Poster: Michael Kay (mhkay)

Questions about the XSLT language specification are best asked on the xsl-list at mulberrytech.com - this list is for questions on matters specific to the Saxon product. The rules are described differently in the XSLT 1.0 and 2.0 specifications, but the effect is the same. In 1.0, a path expression such as ancestor::* returns an unordered set of nodes, but XSLT instructions such as xsl:apply-templates always process the nodes in document order. In 2.0, path expressions such as ancestor::* return a sequence of nodes in document order. Either way, your second answer is the correct one. Michael Kay

    (1-1/1)

    Please register to reply