从搜索参数中过滤 XML
我正在我正在创建的网站上创建一个小型搜索功能。我正在使用 Umbraco CMS,我需要搜索的所有节点都是正在搜索的页面的子节点。现在我有一个包含七个字段的搜索框。三个输入字段和四个下拉列表。
这是我需要从中查找结果的 XML:
<Modellist id="1073" parentID="1052" level="2" writerID="0" creatorID="0" nodeType="1065" template="1066" sortOrder="0" createDate="2010-07-12T20:23:35" updateDate="2010-07-12T21:25:13" nodeName="Piger-girls" urlName="piger-girls" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073" isDoc="">
<title>Girls</title>
<metaDescription></metaDescription>
<metaTitle />
<metaKeywords />
<nameInMenu />
<Model id="1075" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="1" createDate="2010-07-12T20:25:31" updateDate="2010-07-12T21:01:58" nodeName="Lene Madsen" urlName="lene-madsen" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1075" isDoc="">
<title>Lene M</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>014</modelnummer>
<height>120</height>
<size>122</size>
<eyeColor>Blå</eyeColor>
<hairColor>Blond</hairColor>
<shoeSize>26-30</shoeSize>
</Model>
<Model id="1077" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="2" createDate="2010-07-13T19:04:42" updateDate="2010-07-13T19:05:23" nodeName="Julie B" urlName="julie-b" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1077" isDoc="">
<title>Julie B</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>002</modelnummer>
<height>129</height>
<size>104</size>
<eyeColor>Grøn</eyeColor>
<hairColor>Sort</hairColor>
<shoeSize>26-30</shoeSize>
</Model>
<Model id="1078" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="3" createDate="2010-07-13T19:05:38" updateDate="2010-07-13T19:06:06" nodeName="Marlene U" urlName="marlene-u" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1078" isDoc="">
<title>Marlene U</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>007</modelnummer>
<height>89</height>
<size>86</size>
<eyeColor>Grå</eyeColor>
<hairColor>Blond</hairColor>
<shoeSize>26-30</shoeSize>
</Model>
<Model id="1079" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="4" createDate="2010-07-13T19:06:18" updateDate="2010-07-13T19:07:20" nodeName="Louise N" urlName="louise-n" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1079" isDoc="">
<title>Louise N</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>022</modelnummer>
<height>148</height>
<size>152</size>
<eyeColor>Brun</eyeColor>
<hairColor>Brun</hairColor>
<shoeSize>31-35</shoeSize>
</Model>
<Model id="1080" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="5" createDate="2010-07-13T19:07:35" updateDate="2010-07-13T19:07:59" nodeName="Marie A" urlName="marie-a" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1080" isDoc="">
<title>Marie A</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>010</modelnummer>
<height>146</height>
<size>128</size>
<eyeColor>Blå</eyeColor>
<hairColor>Rød</hairColor>
<shoeSize>36-40</shoeSize>
</Model>
<Model id="1081" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="6" createDate="2010-07-13T19:08:22" updateDate="2010-07-13T19:08:53" nodeName="Sandra F" urlName="sandra-f" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1081" isDoc="">
<title>Sandra F</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>013</modelnummer>
<height>126</height>
<size>122</size>
<eyeColor>Blå</eyeColor>
<hairColor>Brun</hairColor>
<shoeSize>31-35</shoeSize>
</Model>
<Model id="1082" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="7" createDate="2010-07-13T19:09:10" updateDate="2010-07-13T19:09:51" nodeName="Laura N" urlName="laura-n" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1082" isDoc="">
<title>Laura N</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>004</modelnummer>
<height>73</height>
<size>74</size>
<eyeColor>Grøn</eyeColor>
<hairColor>Rød</hairColor>
<shoeSize>18-20</shoeSize>
</Model>
<Model id="1083" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="8" createDate="2010-07-13T19:10:09" updateDate="2010-07-13T19:11:19" nodeName="Gitte R" urlName="gitte-r" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1083" isDoc="">
<title>Gitte R</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>017</modelnummer>
<height>105</height>
<size>110</size>
<eyeColor>Grøn</eyeColor>
<hairColor>Brun</hairColor>
<shoeSize>21-25</shoeSize>
</Model>
<Model id="1084" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="9" createDate="2010-07-13T19:11:30" updateDate="2010-07-13T19:12:56" nodeName="Mia H" urlName="mia-h" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1084" isDoc="">
<title>Mia H</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>015</modelnummer>
<height>138</height>
<size>140</size>
<eyeColor>Blå</eyeColor>
<hairColor>Rød</hairColor>
<shoeSize>31-35</shoeSize>
</Model>
名为“size”、“eyeColor”、“hairColor”和“shoeSize”的标签应与我的搜索框中的四个下拉列表相匹配。可以从名为名称的输入字段中搜索名为“标题”的标签。然后我有另一个名为“heightFrom”和“heightTo”的文本字段。在这里,用户可以搜索身高,这应该与名为“height”的 XML 标签相匹配。
我很容易说,如果名称字段不为空,我可以这样做:
<xsl:apply-templates select="$currentPage/*[@isDoc][contains(Exslt.ExsltStrings:lowercase(./title),$name)]">
<xsl:sort data-type="text" select="title" order="ascending"/>
</xsl:apply-templates>
$name 包含搜索到的名称。这将为我提供在“标题”标签中具有搜索名称的所有节点。但我该如何继续下去呢?当然,我可以创建一个选择,其中包含很多(超过 40 个)时间,但这将是一项艰巨的工作,并且将来很难维护。 困难的事情之一是没有一个字段是必填的,所以我不知道哪些字段将被填写。 我还能做点别的吗?
顺便说一句 - URL 可能如下所示: http://my.site/search.aspx?hf=150&ht=&size=62&ec=&hc=&ss=&name=Julie
我拥有所有七个变量的值如下:
<xsl:variable name="heightFrom" select="umbraco.library:Request('hf')"/>
<xsl:variable name="heightTo" select="umbraco.library:Request('ht')"/>
<xsl:variable name="size" select="umbraco.library:Request('size')"/>
<xsl:variable name="eyeColor" select="umbraco.library:Request('ec')"/>
<xsl:variable name="shoeSize" select="umbraco.library:Request('ss')"/>
<xsl:variable name="hairColor" select="umbraco.library:Request('hc')"/>
<xsl:variable name="name" select="Exslt.ExsltStrings:lowercase(umbraco.library:Request('name'))"/>
任何帮助和输入将不胜感激!
预先感谢:)
/Kim
I'm creating a small search function on a site I'm creating. I'm working with Umbraco CMS, and all the nodes that I need to search are children of the page that are being searched on. Right now I have a search box with seven fields. three input fields and four dropdown's.
This is the XML that I need to find my results from:
<Modellist id="1073" parentID="1052" level="2" writerID="0" creatorID="0" nodeType="1065" template="1066" sortOrder="0" createDate="2010-07-12T20:23:35" updateDate="2010-07-12T21:25:13" nodeName="Piger-girls" urlName="piger-girls" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073" isDoc="">
<title>Girls</title>
<metaDescription></metaDescription>
<metaTitle />
<metaKeywords />
<nameInMenu />
<Model id="1075" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="1" createDate="2010-07-12T20:25:31" updateDate="2010-07-12T21:01:58" nodeName="Lene Madsen" urlName="lene-madsen" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1075" isDoc="">
<title>Lene M</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>014</modelnummer>
<height>120</height>
<size>122</size>
<eyeColor>Blå</eyeColor>
<hairColor>Blond</hairColor>
<shoeSize>26-30</shoeSize>
</Model>
<Model id="1077" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="2" createDate="2010-07-13T19:04:42" updateDate="2010-07-13T19:05:23" nodeName="Julie B" urlName="julie-b" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1077" isDoc="">
<title>Julie B</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>002</modelnummer>
<height>129</height>
<size>104</size>
<eyeColor>Grøn</eyeColor>
<hairColor>Sort</hairColor>
<shoeSize>26-30</shoeSize>
</Model>
<Model id="1078" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="3" createDate="2010-07-13T19:05:38" updateDate="2010-07-13T19:06:06" nodeName="Marlene U" urlName="marlene-u" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1078" isDoc="">
<title>Marlene U</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>007</modelnummer>
<height>89</height>
<size>86</size>
<eyeColor>Grå</eyeColor>
<hairColor>Blond</hairColor>
<shoeSize>26-30</shoeSize>
</Model>
<Model id="1079" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="4" createDate="2010-07-13T19:06:18" updateDate="2010-07-13T19:07:20" nodeName="Louise N" urlName="louise-n" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1079" isDoc="">
<title>Louise N</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>022</modelnummer>
<height>148</height>
<size>152</size>
<eyeColor>Brun</eyeColor>
<hairColor>Brun</hairColor>
<shoeSize>31-35</shoeSize>
</Model>
<Model id="1080" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="5" createDate="2010-07-13T19:07:35" updateDate="2010-07-13T19:07:59" nodeName="Marie A" urlName="marie-a" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1080" isDoc="">
<title>Marie A</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>010</modelnummer>
<height>146</height>
<size>128</size>
<eyeColor>Blå</eyeColor>
<hairColor>Rød</hairColor>
<shoeSize>36-40</shoeSize>
</Model>
<Model id="1081" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="6" createDate="2010-07-13T19:08:22" updateDate="2010-07-13T19:08:53" nodeName="Sandra F" urlName="sandra-f" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1081" isDoc="">
<title>Sandra F</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>013</modelnummer>
<height>126</height>
<size>122</size>
<eyeColor>Blå</eyeColor>
<hairColor>Brun</hairColor>
<shoeSize>31-35</shoeSize>
</Model>
<Model id="1082" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="7" createDate="2010-07-13T19:09:10" updateDate="2010-07-13T19:09:51" nodeName="Laura N" urlName="laura-n" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1082" isDoc="">
<title>Laura N</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>004</modelnummer>
<height>73</height>
<size>74</size>
<eyeColor>Grøn</eyeColor>
<hairColor>Rød</hairColor>
<shoeSize>18-20</shoeSize>
</Model>
<Model id="1083" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="8" createDate="2010-07-13T19:10:09" updateDate="2010-07-13T19:11:19" nodeName="Gitte R" urlName="gitte-r" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1083" isDoc="">
<title>Gitte R</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>017</modelnummer>
<height>105</height>
<size>110</size>
<eyeColor>Grøn</eyeColor>
<hairColor>Brun</hairColor>
<shoeSize>21-25</shoeSize>
</Model>
<Model id="1084" parentID="1073" level="3" writerID="0" creatorID="0" nodeType="1067" template="1068" sortOrder="9" createDate="2010-07-13T19:11:30" updateDate="2010-07-13T19:12:56" nodeName="Mia H" urlName="mia-h" writerName="Administrator" creatorName="Administrator" path="-1,1052,1073,1084" isDoc="">
<title>Mia H</title>
<images></images>
<polaroid />
<videoSmall />
<videoLarge />
<modelnummer>015</modelnummer>
<height>138</height>
<size>140</size>
<eyeColor>Blå</eyeColor>
<hairColor>Rød</hairColor>
<shoeSize>31-35</shoeSize>
</Model>
The tags called "size","eyeColor","hairColor" and "shoeSize" shall be matched with the four dropdowns in my search box. The tag called "title" can be searched from a input field called name. And then I have another to textfields called "heightFrom" and "heightTo". here a user can search on height, and this should be matched against the XML-tag called "height".
It's easy for me to say that if the name-field is not empty I can just do this:
<xsl:apply-templates select="$currentPage/*[@isDoc][contains(Exslt.ExsltStrings:lowercase(./title),$name)]">
<xsl:sort data-type="text" select="title" order="ascending"/>
</xsl:apply-templates>
$name contains the searched name. And this will give me all the nodes that have the searched name in the "title"-tag. But how do I get on from this. Of course I can create a choose, with a lot (more than 40) of when's in it, but that would be a big job to that, and very difficult to maintain in the future.
One of the difficult things are that none of the fields are mandatory, so I don't know which of the fields will be filled out.
Can I do anything else?
By the way - a URL could in example look like this:
http://my.site/search.aspx?hf=150&ht=&size=62&ec=&hc=&ss=&name=Julie
I have all of the values in seven variables like this:
<xsl:variable name="heightFrom" select="umbraco.library:Request('hf')"/>
<xsl:variable name="heightTo" select="umbraco.library:Request('ht')"/>
<xsl:variable name="size" select="umbraco.library:Request('size')"/>
<xsl:variable name="eyeColor" select="umbraco.library:Request('ec')"/>
<xsl:variable name="shoeSize" select="umbraco.library:Request('ss')"/>
<xsl:variable name="hairColor" select="umbraco.library:Request('hc')"/>
<xsl:variable name="name" select="Exslt.ExsltStrings:lowercase(umbraco.library:Request('name'))"/>
Any help and inputs will be greatly appreaciated!
Thanks in advance :)
/Kim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您只需要在正确的上下文中使用 XPath 表达式。该样式表:
结果:
I think you only need an XPath expression in the correct context. This styleshet:
Result: