[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] search against index


Subject: [xsl] search against index
From: "bryan" <bry@xxxxxxxxxx>
Date: Thu, 7 Aug 2003 16:04:51 +0200

I have a parameter $string

And I do <xsl:apply-templates select="index[contains(@value,$string)]"/>

This works great, but I want to do a search with string + string, in
other words given limitations of xslt, a search with multiple contains.

So for example:
<list>
<index value="a string of values here">
result
</index>
<index value="another string here">
result2
</index>
</list>


if $string = "another"

this returns the second index node, if $string  = "another + here"

then it still returns the second index node, if $string = "string +
here" it returns both nodes.

What I figured I'd have to do is the following
<xsl:template match="/">
<return>
<xsl:variable name="returnNode">
<xsl:choose>
<xsl:when test="contains($string,'+')">
<xsl:apply-templates select="index[contains(@value,$string)]"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="nodesetreturner">
<xsl:with-param name="searchstring" select="$string"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:copy-of select="gen:node-set($returnNode)"/>
</return>
</xsl:template>

<xsl:template name="nodesetreturner">
<xsl:param name="searchstring"/>
<xsl:param name="tempnodeset"/>
<xsl:param name="exit"/>

<xsl:choose when test="contains($searchstring,'+') and
not(gen:node-set($tempnodeset)/*)">
<xsl:variable name="locnodeset">
<list>
<xsl:apply-templates
select="index[contains(@value,substring-before($searchstring,'+'))]"/>
</list>
</xsl:variable>
<xsl:call-template name="nodeseteval">
<xsl:with-param name="locnodeset" select="$locnodeset"/>
<xsl:with-param name="searchstring"
select="substring-after(@value,'+')"/>
</xsl:call-template>

</xsl:when>
<xsl:when test="contains($searchstring,'+') and
gen:node-set($tempnodeset)/*">
<xsl:variable name="locnodeset">
<list>
<xsl:apply-templates
select="gen:node-set($tempnodeset)/list/index[contains(@value,substring-
before($searchstring,'+'))]"/>
</list>
</xsl:variable>

..............and so forth I don't want to write the whole thing out
here, it's pretty obvious what the procedure is. 

The thing is I'm wondering if there's a better way to go through it,
this is pretty resource intensive, not to mention tedious coding. 

But really I can't see anyway but building a rtf and then trimming that
with successive passes. 


Also would like if anyone has examples of how this would be improved in
xslt 2.0 as I think it should be, perhaps via grouping.

</xsl:when>
<xsl:when test="$exit = 'true' and not(gen:node-set($tempnodeset)/*)">
<p>there were no search results</p>
</xsl:when>


</xsl:template>

<xsl:template name="nodeseteval">
<xsl:param name="$locnodeset"/>
<xsl:param name="$locsearchstring"/>
<xsl:choose>
<xsl:when test="gen:node-set($locnodeset)/list/*">
<xsl:call-template name="nodesetreturner">
<xsl:with-param name="searchstring" select="$locsearchstring"/>
<xsl:with-param name="tempnodeset" select="$locnodeset"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="nodesetreturner">
<xsl:with-param name="exit" select="'true'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords