In looking to count the number of instances of an XML element I was looking about for a piece of XSLT. Every example I came across had the xsl 'number' element within the 'for-each' element, which meant that the XSLT had to parse the element I was counting first. I didn't want to have a 'for-each' involved at all, but eventually I was in luck, and it's much easier that using a 'number' element:
<xsl:value-of select="count(elementname)" />
I was directed to this solution by experts-exchange: http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21294193.html
However, if you do want to perform counting operations, this is an excellent starting point: http://www.w3schools.com/Xsl/el_number.asp
And for more general XSLt references:
- http://www.developer.com/xml/article.php/3383961 - Good for traversing XML
- http://www.15seconds.com/issue/031105.htm - Paging
- http://www.dpawson.co.uk/xsl/rev2/dates.html - Check this whole site for XSLt goodness
- http://projects.ischool.washington.edu/tabrooks/545/ContentManagement/PassingParameters.htm - Passing parameters to XSLt
- http://www.w3.org/TR/xpath - As always, the standard comes from W3C.org
- http://geekswithblogs.net/workdog/archive/2007/02/08/105858.aspx - Lots of date formatting
I highly recommend D. Pawson's site as it is basically a massive list of examples and explanations for just about everything anyone would ever want to do in XSLt.
Also, of course, the http://www.developer.com/xml/article.php/3383961 article will tell you everything you need to know about traversing XML - especially useful if you are writing code which needs to build, navigate or parse XML.
No comments:
Post a Comment