xml - What is best XSLT XPath performance in my scenario? -
i have question xslt xpath performance. if in following example.
which of following options has best performance:
<xsl:for-each select="//cd">
or
<xsl:for-each select="//catalog/cd">
xml data:
<?xml version="1.0" encoding="utf-8"?> <root> <catalog> <cd> <title>empire burlesque</title> <artist>bob dylan</artist> </cd> <cd> <title>hide heart</title> <artist>bonnie tyler</artist> </cd> </catalog> <catalog> <cd> <title>greatest hits</title> <artist>dolly parton</artist> <cd> <title>still got blues</title> <artist>gary moore</artist> </cd> </catalog> </root>
xslt stylesheet:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <body> <h2>my cd collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>title</th> <th>artist</th> </tr> <xsl:for-each select="//cd"> <tr> <td><xsl:value-of select="title" /></td> <td><xsl:value-of select="artist" /></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
wich has best performance?
(i have made smaller easier example, in real case have more complex data stracture)
the possible answer question "it depends on processor". rule should avoid using //
un-necessarily, clever processor may able optimise simple //something
absolute paths (e.g. using hash table nodes name) faster specified /root/catalog/cd
.
you have profile specific processor on specific data.
Comments
Post a Comment