简体   繁体   English

使用xpath从xml文件获取区域

[英]get region from xml file using xpath

i have one xml file with content of region, state, city name 我有一个XML文件,其中包含region, state, city name

<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>

i am try to get region name if entered city name is match in xml file. 如果输入的城市名称与xml文件匹配,我会尝试获取区域名称。

here is one variable there value in Ahemdabad (city Name) 这是Ahemdabad (城市名称)中的一个值

here is my xpath:- 这是我的xpath:

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

when i try City name into direct xpath as a string its work. 当我尝试将City name转换为直接xpath作为字符串时,其工作原理。

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

its not return me anything . 它什么也没回报我。
Please help me to solve my xpath Problem. 请帮助我解决我的xpath问题。
thanks. 谢谢。

Guess the problem is with the declaration syntax. 猜猜问题出在声明语法上。 When using xpath in Xquery we declare variable as let $var1 = "Ahemdabad" 在Xquery中使用xpath时,我们将变量声明为let $ var1 =“ Ahemdabad”

and in case XSLT is used declaration is made like 在使用XSLT的情况下,声明如下

value

And the declared variable is addressed in the necessary location. 并且已声明的变量在必要的位置进行寻址。 Can you please explain how are you using it? 您能解释一下如何使用吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM