2013-05-06 40 views
0

從XML文件中獲取區域!我曾在region, state, city name
使用XPath

<childrens> 
    <child_1 entity_id="1" value="Region"> 
     <child_2 entity_id="2" value="Asia"> 
      <child_3 entity_id="3" value="Gujarat"> 
       <child_4 entity_id="4" value="Ahemdabad" /> 
      </child_3> 
     </child_2> 
    </child_1> 
</childrens> 

我是試圖讓區域名稱,如果輸入城市名稱是匹配的xml文件內容中的一個XML文件。

這裏是一個變量存在價值Ahemdabad(城市名)

這裏是我的XPath: -

value = 'Ahemdabad'; 
      var xPath = '//*[@value= "' + value+'"]' + 
          '/../../@entity_id'; 

當我嘗試城市名稱爲直接的XPath作爲一個字符串的工作。

  var xPath = '//*[@value= "Ahemdabad"]' + 
          '/../../@entity_id'; 

它不回報我什麼。
請幫我解決我的xpath問題。
謝謝。

+1

我沒有看到問題是什麼,似乎工作。看看[this](http://jsfiddle.net/LwQeM/1/) – 2013-05-06 11:15:56

回答

-1

猜測問題出在聲明語法上。當XQuery中使用XPath我們聲明變量 讓$ VAR1 =「Ahemdabad」

,並在情況下,XSLT是用來聲明是由像

而聲明的變量在必要的位置尋址。你能解釋你如何使用它?