2010-07-13 28 views
0

我在創建的網站上創建小型搜索功能。我正在使用Umbraco CMS,並且我需要搜索的所有節點都是正在搜索的頁面的子項。現在我有一個有七個字段的搜索框。三個輸入字段和四個下拉菜單。從搜索參數過濾XML

這是我需要從找到我的結果的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> 

所謂的「大小」的標籤,「眼睛顏色」,「hairColor的」和「shoeSize」應與匹配我的搜索框中有四個下拉菜單。稱爲「標題」的標籤可以從稱爲名稱的輸入字段中搜索。然後我有另一個名爲「heightFrom」和「heightTo」的文本框。這裏用戶可以在高度上進行搜索,並且這應該與稱爲「高度」的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> 

$名稱中包含搜索姓名。這將給我所有在「標題」 - 標籤中具有搜索名稱的節點。但是,我怎麼從這裏開始。當然,我可以創造一個選擇,有很多(超過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'))"/> 

任何幫助和投入將大大appreaciated !

感謝提前:)

/金

+0

你能說我通情達理的你,如果我說你想匹配的變量條件的'Model'元素? – 2010-07-13 23:23:34

+0

是的,這是正確的。也許我沒有這麼好描述。但你是對的。我想要符合搜索標準的模型元素。如果你有提示或提示,只是這樣說,它可能會導致我的方向正確:) - 謝謝。 – 2010-07-14 07:03:30

回答

1

我想你只需要在正確的上下文中的XPath表達式。這styleshet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:param name="heightFrom" select="120"/> 
    <xsl:param name="heightTo" select="130"/> 
    <xsl:param name="size" /> 
    <xsl:param name="eyeColor" /> 
    <xsl:param name="shoeSize" /> 
    <xsl:param name="hairColor" /> 
    <xsl:param name="name" /> 
    <xsl:template match="/"> 
     <Modellist> 
      <xsl:copy-of select="*/Model[height >= $heightFrom and $heightTo >= height 
           or 
          height >= $heightFrom and not($heightTo) 
           or 
          not($heightFrom) and $heightTo >= height] 
          [size = $size or not($size)] 
          [eyeColor = $eyeColor or not($eyeColor)] 
          [$shoeSize >= substring-before(shoeSize,'-') 
           and 
          substring-after(shoeSize,'-') >= $shoeSize 
           or 
          not($shoeSize)] 
          [hairColor = $hairColor or not($hairColor)] 
          [title = $name or not($name)]"/> 
     </Modellist> 
    </xsl:template> 
</xsl:stylesheet> 

結果:

<Modellist> 
    <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="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> 
</Modellist>