Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Mon, 17 Mar 2008 23:05:43 +0800,    group: microsoft.public.xsl        back       


use contains to search through multiple nodes.   
Dear Sir,

I am using MSXML and XSLT to search one XML. I can use "contains" to search 
through all child nodes, I do not know how can search into other nodes of 
parent parent nodes.

I got below XML.
---------------------------XML--------------------------------
<agendas>
<agenda>
<id>1112</id>
<data>
<content>
<title>this is the title # 2</title>
</content>
<ref>GT355-332-234</ref>
</data>
<category>Finance</category>
</agenda>

.............

</agendas>

---------------------------End of XML ----------------------

I need to search keyword on <title>, also need to check <category> = certain 
value.
I use below XSLT to search title node, how do I check <category> node match 
one value? should I use apply-templates twice or is there other solutions?

----------------------------------  
XSLT -----------------------------------------
<!-- upper and lower case for case incensitive search.-->
  <xsl:variable name="lc">abcdefghijklmnopqrstuvwxyz</xsl:variable>
  <xsl:variable name="UC">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>

  <xsl:template name="filter" match="/">
    <!-- this will filter out data by keyword and/or datetime.-->
    <xsl:apply-templates 
select="/agendas/agenda/data/content[contains(translate(.,$UC,$lc), 
$Keyword)]">
    </xsl:apply-templates>

  </xsl:template>
---------------------------------- END of 
XSLT ----------------------------------

-- 
Guoqi Zheng
http://www.chinasoftware.eu
date: Mon, 17 Mar 2008 23:05:43 +0800   author:   Guoqi Zheng

Re: use contains to search through multiple nodes.   
Guoqi Zheng wrote:

> I need to search keyword on <title>, also need to check <category> = 
> certain value.
> I use below XSLT to search title node, how do I check <category> node 
> match one value? should I use apply-templates twice or is there other 
> solutions?

You can use a predicate e.g.

>    <xsl:apply-templates 
> select="/agendas/agenda/data/content[contains(translate(.,$UC,$lc), 
> $Keyword)]">

  <xsl:apply-templates
    select="/agendas/agenda[category =
$category]/data/content[contains(translate(.,$UC,$lc), $Keyword)]">

that filters out the agenda elements having a category child element
with content being equal to the variable or parameter named 'category'.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Mon, 17 Mar 2008 16:26:31 +0100   author:   Martin Honnen

Re: use contains to search through multiple nodes.   
Great! what about if the category node is under the node of <metadata> 
instead of directly under<agenda>? The agenda data can be something like

-------------------------------------- 
<agenda>
<id>1112</id>
<data>
<content>
<title>this is the title # 2</title>
</content>
<ref>GT355-332-234</ref>
</data>
<metadata>
<category>Finance</category>
</metadata>
</agenda>

-----------------------------

What should I do in this case then?

Thanks for great help.

Regards,

Guoqi Zheng


"Martin Honnen"  дÈëÏûÏ¢ 
news:uBRvLNEiIHA.2304@TK2MSFTNGP05.phx.gbl...
> Guoqi Zheng wrote:
>
>> I need to search keyword on <title>, also need to check <category> =
>> certain value.
>> I use below XSLT to search title node, how do I check <category> node
>> match one value? should I use apply-templates twice or is there other
>> solutions?
>
> You can use a predicate e.g.
>
>>    <xsl:apply-templates
>> select="/agendas/agenda/data/content[contains(translate(.,$UC,$lc),
>> $Keyword)]">
>
>  <xsl:apply-templates
>    select="/agendas/agenda[category =
> $category]/data/content[contains(translate(.,$UC,$lc), $Keyword)]">
>
> that filters out the agenda elements having a category child element
> with content being equal to the variable or parameter named 'category'.
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
date: Tue, 18 Mar 2008 00:13:19 +0800   author:   Guoqi Zheng

Re: use contains to search through multiple nodes.   
Guoqi Zheng wrote:
> Great! what about if the category node is under the node of <metadata> 
> instead of directly under<agenda>? The agenda data can be something like
> 
> -------------------------------------- <agenda>
> <id>1112</id>
> <data>
> <content>
> <title>this is the title # 2</title>
> </content>
> <ref>GT355-332-234</ref>
> </data>
> <metadata>
> <category>Finance</category>
> </metadata>
> </agenda>


Change

>>  <xsl:apply-templates
>>    select="/agendas/agenda[category =
>> $category]/data/content[contains(translate(.,$UC,$lc), $Keyword)]">

to

 <xsl:apply-templates
    select="/agendas/agenda[metadata/category =
$category]/data/content[contains(translate(.,$UC,$lc), $Keyword)]">


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Mon, 17 Mar 2008 17:18:04 +0100   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us