xsl-list
[Top] [All Lists]

Re: xsl:key only checks first child, need to check all

2005-11-05 17:15:05

Avoid using // (especially since you have a key already set up so you
don't need to repeat the search over the whole document. Also you
usually have a better experience initially writing your code for a
command line or editor based engine rather than for a browser. Browsers
are not really designed to report errors.

This would be easier to do in two passes, but since you want it to run
in firefox which doesn't have a node-set() extension, here's I one-pass
solution that probably does what you want.

$ saxon a.xml a.xsl
<html>culture<br>
   -----Deloria, Ella C.<br>
   -----Rice, Julian<br>
   texts<br>
   -----Deloria, Ella C.<br>
   -----Rice, Julian<br>

</html>



<xsl:stylesheet version="1.0"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>



    <xsl:key name = "topics" match = " topic " use = " . " />
    <xsl:key name = "name" match = "author/name" use = "." />

    <xsl:template match = "/" >
        <html>
                <xsl:for-each select =
        
"/sources/source/topics/topic[generate-id()=generate-id(key('topics',.))]
        " >
                    <xsl:sort select = " . " />
                    <xsl:variable name = "currentTopic" select = " . "
        />

                    <xsl:value-of select = " $currentTopic " />
                    <br /><xsl:text>&#10;</xsl:text>

                    <xsl:for-each select =
                    "key('name',key('topics',$currentTopic)/../../authors
                    / author /
                    name)[generate-id()=generate-id(key('name',.))]">
                        <xsl:sort select = " . " />

                        <xsl:text>-----</xsl:text>
                        <xsl:value-of select = "." />
                        <br /><xsl:text>&#10;</xsl:text>
                    </xsl:for-each>

                </xsl:for-each>
        </html>
    </xsl:template>

</xsl:stylesheet>


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>