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

Re: word search a document and eliminate duplicate re

Subject: Re: word search a document and eliminate duplicate results
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Sun, 09 Jan 2005 10:40:24 +0100
re word search
hi,

The search term ($target1) may appear within a <p>, within a <note>, or within a <p> that is within a <note>. If it occurs anywhere within a note, then I need not only the note but the paragraph in which it resides. Which further muddies the water because if a paragraph contains the search term and that same paragraph also contains a <note> that contains the search term, I still need to output that paragraph only once.

The problem is caused by this template:


<xsl:template match="text()" mode="search">
    <xsl:param name="term" select="''"/>
    <xsl:param name="element" select="''"/>
        <xsl:choose>
            <xsl:when test="contains(.,$term)">
                <xsl:for-each select="ancestor::p[not(parent::note)][1]">
                    <xsl:apply-templates/>
                    <hr/><br/>
                </xsl:for-each>
            </xsl:when>
            <xsl:otherwise/>
        </xsl:choose>
</xsl:template>

It makes a textual copy of its container for each and every text node that contains the searched text.
You could add an expression to the 'xsl:when' that is only true at the first match:


<xsl:template match="text()" mode="search">
<xsl:param name="term" select="''"/>
<xsl:param name="element" select="''"/>
<xsl:choose>
<xsl:when test="contains(.,$term) and generate-id()=generate-id(ancestor::p[not(parent::note)][1]//text()[contains(.,$term)])">
<xsl:apply-templates select="ancestor::p[not(parent::note)][1]"/>
<hr/><br/>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:template>



You might also avoid the duplication by copying at the top rather than after diving in the tree. e.g.:


<xsl:template match="/">
<div>
<xsl:for-each select="/*/*[local-name()=document('')/*/xsl:variable[@name='select-elements']/item][contains(.,$target1)]">
<xsl:copy-of select="."/>
<hr/>
</xsl:for-each>
</div>
</xsl:template>




regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
Vincit omnia simplicitas
Keep it simple

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.