Subject: Using XSLT to search XML From: e thurairajah <ethurairajah@xxxxxxxxx> Date: Wed, 25 Oct 2000 04:41:47 -0700 (PDT) |
Hi, I am a newbie to the list and have already been through the FAQs. I am hoping someone can offer suggestions on how to best approach the following problem: - We have some club listing information (data) in XML format and have written a Java servlet that uses the Saxon classes to perform searches given a specific stylesheet and search parameters. - Users need to be able search on any one of about 4 parameters (clubname, location, postcode, etc), any one of which can be null. However, at least one search parameter is required before a search is executed. - The search should be flexible enough to match any combination of parameters and should be able to exclude null parameters from the "select." - Our current thinking (not reflected in the sample below) is to build an XSL variable that would contain the entire search string, and be used in the select query. <xsl:choose> <xsl:when test="$location != ''"> <xsl:variable name="Vlocation" value="concat('contans(',$location,',location)'" /> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> ... and so on - Currently we are able to do a basic OR type search that returns a result if any of the search parameters matches a listing. It does not handle null parameters or other combinations. - Below I have included extracts from both the data and XSLT files. Please let me know if any of the above needs further clarification. thanks in advance, ema thurairajah. ethurairajah@xxxxxxxxx --------- XSLT File ---------------------------------- <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes" /> <xsl:param name="clubname" /> <xsl:param name="eventname" /> <xsl:param name="clubpostcode" /> <xsl:param name="location" /> <xsl:template match="/" > <xsl:value-of select="$clubname" /> <xsl:value-of select="$eventname" /> Club Post Code: *** <xsl:value-of select="$clubpostcode" /> *** <xsl:value-of select="$location" /> <xsl:apply-templates mode="dump" select="/feed/content.item/content.body/listing[contains($location, location) or contains($clubpostcode, clubpostcode) or contains($clubname, clubname) or contains($eventname, eventname)]"> <xsl:with-param name="clubname" select="$clubname" /> <xsl:with-param name="eventname" select="$eventname" /> <xsl:with-param name="clubpostcode" select="$clubpostcode" /> <xsl:with-param name="location" select="$location" /> </xsl:apply-templates> <hr /> </xsl:template> <xsl:template match="listing" mode="dump"> <xsl:param name="clubname" /> <xsl:param name="eventname" /> <xsl:param name="clubpostcode" /> <xsl:param name="location" /> <hr /> <hr /> <xsl:value-of select="clubname" /> <xsl:value-of select="clubaddress"/> <xsl:value-of select="clubcity" /><br /> -<xsl:value-of select="clubcounty" /><br /> -<xsl:value-of select="clubpostcode" /><br /> -<xsl:value-of select="clubcountry" /><br /> -<xsl:value-of select="location" /><br /> -<xsl:value-of select="clubtel" /><br /> -<xsl:value-of select="eventname" /><br /> -<xsl:value-of select="dateofevent" /><br /> -<xsl:value-of select="musicstyle" /><br /> -<xsl:value-of select="dresscode" /><br /> -<xsl:value-of select="openingtimes" /><br /> -<xsl:value-of select="prices" /><br /> -<xsl:value-of select="residents" /><br /> -<xsl:value-of select="entertainment" /><br /> -<xsl:value-of select="eventname" /><br /> <hr /> </xsl:template> </xsl:stylesheet> ----------- End XSLT File ----------------------------- ... and the data ----------- XML File ---------------------------------- <?xml version="1.0" encoding="UTF-8"?> <content.item id="32432432432-43242"> <content.body> <listing> <clubname>Ministry Of Sound</clubname> <clubaddress>103 Gaunt Street</clubaddress> <clubcity><![CDATA[Elephant & Castle]]></clubcity> <clubcounty>London</clubcounty> <clubpostcode>SE1</clubpostcode> <clubcountry>England</clubcountry> <location>London</location> <clubtel>0207 378 6528</clubtel> <eventname>Move</eventname> <dateofevent><![CDATA[20/10/2000]]></dateofevent> <musicstyle><![CDATA[House & Garage]]></musicstyle> <dresscode><![CDATA[Smart & Funky Club Wear]]></dresscode> <openingtimes><![CDATA[10.30pm - 6am]]></openingtimes> <prices><![CDATA[£6 / £10]]></prices> <residents>Spencer Broughton</residents> <entertainment> Spoony, Jason Kaye, Norris Da Boss Windross, Alex P, Matt White, Relentless, CKP Blakey and Neat </entertainment> </listing> <listing> <clubname>Ministry Of Sound 2</clubname> <clubaddress>103 Gaunt Street</clubaddress> <clubcity>Tottenham</clubcity> <clubcounty>London</clubcounty> <clubpostcode>SW1 6DP</clubpostcode> <clubcountry>England</clubcountry> <location>London</location> <clubtel>0207 378 6528</clubtel> <eventname>Groove</eventname> <dateofevent><![CDATA[20/10/2000]]></dateofevent> <musicstyle><![CDATA[House & Garage]]></musicstyle> <dresscode><![CDATA[Smart & Funky Club Wear]]></dresscode> <openingtimes><![CDATA[10.30pm - 6am]]></openingtimes> <prices><![CDATA[£6 / £10]]></prices> <residents>Spencer Broughton</residents> <entertainment> Spoony, Jason Kaye, Norris Da Boss Windross, Alex P, Matt White, Relentless, CKP Blakey and Neat </entertainment> </listing> <listing> <clubname>Zeta</clubname> <clubaddress>103 Gaunt Street</clubaddress> <clubcity><![CDATA[Marble Arch]]></clubcity> <clubcounty>London</clubcounty> <clubpostcode>W1 6DP</clubpostcode> <clubcountry>England</clubcountry> <location>Rotterdam</location> <clubtel>0207 378 6528</clubtel> <eventname>Move</eventname> <dateofevent><![CDATA[20/10/2000]]></dateofevent> <musicstyle><![CDATA[House & Garage]]></musicstyle> <dresscode><![CDATA[Smart & Funky Club Wear]]></dresscode> <openingtimes><![CDATA[10.30pm - 6am]]></openingtimes> <prices><![CDATA[£6 / £10]]></prices> <residents>Spencer Broughton</residents> <entertainment> Spoony, Jason Kaye, Norris Da Boss Windross, Alex P, Matt White, Relentless, CKP Blakey and Neat </entertainment> </listing> </content.body> </content.item> ----------- End XML File ------------------------------ __________________________________________________ Do You Yahoo!? Yahoo! Messenger - Talk while you surf! It's FREE. http://im.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: MSXM schema plans, Andrew Kimball | Thread | Re: Using XSLT to search XML, Jeni Tennison |
MSXM schema plans, Eckenberger Axel | Date | 2xml files -> one xml file and sear, Michael Hoffmann |
Month |