[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Needing suggestions for better XSL logic

Subject: Needing suggestions for better XSL logic
From: <Kevin.Weiss@xxxxxxx>
Date: Wed, 25 Oct 2006 12:25:35 -0400
kevin weiss
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.