This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > March 2005 > Searching xml with xslt's?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Searching xml with xslt's?
Ken Adams

2005-03-16, 7:03 pm

Ok, I want to have an xslt that will search a list of subscriptions
elements: eg
<subscription>
<user id="ken@ken.ca"/>
<destination city="Denver" country="USA" region="CO"/>
<date from="2005-07-24" to="2005-07-29"/>
<use>
<default lastRefresh="2005-01-23T12:20:00Z" refresh="10"/>
<connector id="c00002"/>
</use>
<event>
<name> Soccer Competition</name>
<category> Sport</category>
</event>
</subscription>

So I want to be able to pass in parameters representing the values I can
search for such as:
<xsl:param name="id">
<xsl:param name="city">
<xsl:param name="region">
<xsl:param name="country">
<xsl:param name="from">
<xsl:param name="to">
<xsl:param name="eventName">
<xsl:param name="eventCategory">

And somehow I want to search for these items, but the thing is I want it to
be able to search for all items that match the criteria but also be able to
handle the event that some of the parameters haven't been passed in. In
other words say if country isin't passed in I want it to return all the
subscriptions that match the other criteria and not care what the country
is. What is the best way to do this. A further requirement would be to say
if a country value was set to c, only return the elements that have a
country that starts with c, assuming the other parameters match. I have been
trying to mess with xPath and xslt but I can't quite figure it out. Any help
would greatly be appreciated. Thanks a bunch.

Ken


Martin Honnen

2005-03-17, 6:44 pm



Ken Adams wrote:

> Ok, I want to have an xslt that will search a list of subscriptions
> elements: eg
> <subscription>
> <user id="ken@ken.ca"/>
> <destination city="Denver" country="USA" region="CO"/>
> <date from="2005-07-24" to="2005-07-29"/>
> <use>
> <default lastRefresh="2005-01-23T12:20:00Z" refresh="10"/>
> <connector id="c00002"/>
> </use>
> <event>
> <name> Soccer Competition</name>
> <category> Sport</category>
> </event>
> </subscription>
>
> So I want to be able to pass in parameters representing the values I can
> search for such as:
> <xsl:param name="id">
> <xsl:param name="city">
> <xsl:param name="region">
> <xsl:param name="country">
> <xsl:param name="from">
> <xsl:param name="to">
> <xsl:param name="eventName">
> <xsl:param name="eventCategory">
>
> And somehow I want to search for these items, but the thing is I want it to
> be able to search for all items that match the criteria but also be able to
> handle the event that some of the parameters haven't been passed in. In
> other words say if country isin't passed in I want it to return all the
> subscriptions that match the other criteria and not care what the country
> is.



You could write a template that copies all destination elements when the
paramter is not set
not($city)
or when the parameter matches
not($city) or @city = $city
and then use a logical and expression for other parameters e.g.:

<xsl:template match="destination">
<xsl:if test="(not($city) or @city = $city) and (not($region) or
@region = $region) and (not($country) or @country = $country)">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:if>
</xsl:template>


--

Martin Honnen
http://JavaScript.FAQTs.com/
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews