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

Re: search against index

Subject: Re: search against index
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Thu, 07 Aug 2003 15:58:51 +0100 (WEST)
index of string in xsl
Hi.

Citando bryan <bry@xxxxxxxxxx>:

} 
} 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.
} 
(...)

Try this:
  <xsl:param name="string" select="''"/>
  <xsl:template match="list">
    <result>
      <xsl:call-template name="search">
        <xsl:with-param name="nodes" select="index"/>
        <xsl:with-param name="string" select="$string"/>
      </xsl:call-template>
    </result>
  </xsl:template>

  <xsl:template name="search">
    <xsl:param name="nodes" select="/.."/>
    <xsl:param name="string" select="''"/>
    <xsl:choose>
      <xsl:when test="contains($string,'+')">
        <xsl:call-template name="search">
          <xsl:with-param name="nodes" select="$nodes[contains(@value,normalize-space
(substring-before($string,'+')))]"/>
          <xsl:with-param name="string" select="normalize-space(substring-after
($string,'+'))"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy-of select="$nodes[contains(@value,$string)]"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Hope this helps you.

Regards,
Americo Albuquerque
___________________________________________________________________

O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt


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


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.