extra element returned in sitecore xpath query in xslt
In a number of xslt's I've written I've used the following to retrieve a set of all the document of a particular type within Sitecore.
<xsl:variable name="documents" select="//item[@template='docu开发者_如何学编程ment type']" />
It almost works as expected except that one extra blank element is always returned and I'm not sure why. Perhaps the above is also returning the template itself but I don't know how to verify this.
gah sorry. It seems the following works.
<xsl:variable name="home" select="sc:item('/sitecore/content/home',.)" />
<xsl:variable name="documents" select="$home//item[@template='document type']" />
I had tried a similar thing earlier but it didn't work
<xsl:variable name="documents" select="/sitecore/content/home//item[@template='document type']" />
I need to go read more xslt tutorials ;)
Whilst you can achieve this through an XSLT selection, searching through all descendants of a site, particularly starting at the Home node, can be a very expensive operation and is often a sign that the architecture needs to be looked at again. Are you sure this is what you need to do in your site, or perhaps you need to rethink what you are trying to achieve?
If you have these document templates spread out across all of your site and you do need to find them, a Lucene Index is going to be much better for you if you have a lot of content. Take a look at the Advanced Database Crawler.
精彩评论