[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Muenchian method, and keys 'n stuff
Hi Dave, > but I can't figure out a way of iterating over an alphabet, and > processing the records to 'announce' the missing letters (i.e. no > books beginning with that letter) I'd just iterate over the alphabet held in a string, with a recursive template. It starts off with the whole alphabet and gradually whittles it down letter by letter until there's no alphabet left: <xsl:template name="alphabetical"> <xsl:param name="alphabet" select="'abcdefghijklmnopqrstuvwxyz'" /> <xsl:if test="$alphabet != ''"> <xsl:variable name="letter" select="substring($alphabet, 1, 1)" /> ... do things with the letter ... <xsl:call-template name="alphabetical"> <xsl:with-param name="alphabet" select="substring($alphabet, 2)" /> </xsl:call-template> </xsl:if> </xsl:template> In your case, the thing you want to do with the letter is identify those r elements whose Ra/lett is that letter. You can do this with the key that you've made, as follows: <xsl:template name="alphabetical"> <xsl:param name="alphabet" select="'abcdefghijklmnopqrstuvwxyz'" /> <xsl:if test="$alphabet != ''"> <xsl:variable name="letter" select="substring($alphabet, 1, 1)" /> <xsl:variable name="auths" select="key('auth', $letter)" /> <xsl:choose> <xsl:when test="$auths"> <h2> The letter <xsl:value-of select="translate($letter, $l, $u)" /> </h2> <xsl:for-each select="$auths"> <h3><xsl:value-of select="Ra/au" /></h3> </xsl:for-each> </xsl:when> <xsl:otherwise> <p> There are no authors beginning with <xsl:value-of select="$letter" /> </p> </xsl:otherwise> </xsl:choose> <xsl:call-template name="alphabetical"> <xsl:with-param name="alphabet" select="substring($alphabet, 2)" /> </xsl:call-template> </xsl:if> </xsl:template> To call the template, all you need is: <xsl:call-template name="alphabetical" /> Note that the key will give you all r elements with the same Ra/lett, and as such it won't be scoped within the 'adventure'. To get the scoping, you need to do one of the following: - include the adventure's (generated) ID within the key, and pass that ID to the alphabetical template - don't use the key to retrieve the rs with a particular Ra/lett, just use r[Ra/lett = $letter] instead (less efficient than a key, probably) Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|