[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Needing suggestions for better XSL logic
Hi all, I'm trying to find a better alternative to our current test XSL template. Currently, we have the following XML file structure (extremely simplified from the original): <resultset> <term> <termname>First Term</termname> <termattrs> <termdef>This is the firstterm description.</termdef> </termattrs> </term> <term> <termname>Second Term</termname> <termattrs> <termdef>This is the second term description.</termdef> </termattrs> </term> </resultset> We're trying build a glossary of the terms listed in alphabetical order. In other words, after the translation, viewing the XML (in IE) should produce an output similar to the following: A B ... F First Term (This is the first term description.) ... S Second Term (This is the second term description.) ... Z Unfortunately, our current XSL logic involves an <xsl:for-each> loop which tests whether the first letter of <termname> begins with a letter. However, this is done for *each* letter, so we have duplicate code, i.e.: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ... <p>A</p> <xsl:template match="/resultset"> <xsl:for-each select="term"> <xsl:if test="starts-with(termname, 'A') or starts-with(termname, 'a')"> <xsl:value-of select="termname" /> <xsl:value-of select="termattrs/termdef" /> </xsl:if> </xsl:for-each> <p>B</p> <xsl:template match="/resultset"> <xsl:for-each select="term"> <xsl:if test="starts-with(termname, 'B') or starts-with(termname, 'b')"> <xsl:value-of select="termname" /> <xsl:value-of select="termattrs/termdef" /> </xsl:if> </xsl:for-each> ... </xsl:template> </xsl:stylesheet> Is there a better method than using multiple <xsl:for-each> loops? We've looked into other options (e.g. xsl:for-each-group, using multiple apply-templates), but nothing produces our desired output. My brain is mush right now, so any suggestions are greatly appreciated. If there's anything else you need from me, please let me know. Thanks in advance! Kevin Weiss
|
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
|