[英]Need help to find a correct Xpath for XSLT code
I have an XML below and need a correct xpath for the following condition: 我在下面有XML,并且对于以下情况需要正确的xpath:
Look for Phone_Device_Type_ID = Cell # 1
Look for Communication_Usage_Type_ID = WORK
Display Formatted_Phone
My xpath: 我的xpath:
wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/wd:Phone_Data[
wd:Phone_Device_Type_Reference/wd:ID='Cell # 1'
]/wd:Usage_Data[wd:Type_Data/wd:Type_Reference/wd:ID='WORK']/@wd:Formatted_Phone
Sample XML 样本XML
<wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
<wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
<wd:International_Phone_Code>1</wd:International_Phone_Code>
<wd:Area_Code>847</wd:Area_Code>
<wd:Phone_Number>8675309</wd:Phone_Number>
<wd:Phone_Device_Type_Reference>
<wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
<wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
</wd:Phone_Device_Type_Reference>
<wd:Usage_Data wd:Public="1">
<wd:Type_Data wd:Primary="0">
<wd:Type_Reference>
<wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
<wd:ID wd:type="Communication_Usage_Type_ID">WORK</wd:ID>
</wd:Type_Reference>
</wd:Type_Data>
</wd:Usage_Data>
</wd:Phone_Data>
<wd:Phone_Data wd:Formatted_Phone="+1 (847) 8675309">
<wd:Country_ISO_Code>USA</wd:Country_ISO_Code>
<wd:International_Phone_Code>1</wd:International_Phone_Code>
<wd:Area_Code>847</wd:Area_Code>
<wd:Phone_Number>8675309</wd:Phone_Number>
<wd:Phone_Device_Type_Reference>
<wd:ID wd:type="WID">1cfe702a6234015468e3527fd07c1001</wd:ID>
<wd:ID wd:type="Phone_Device_Type_ID">Cell # 1</wd:ID>
</wd:Phone_Device_Type_Reference>
<wd:Usage_Data wd:Public="1">
<wd:Type_Data wd:Primary="0">
<wd:Type_Reference>
<wd:ID wd:type="WID">1f27f250dfaa4724ab1e1617174281e4</wd:ID>
<wd:ID wd:type="Communication_Usage_Type_ID">HOME</wd:ID>
</wd:Type_Reference>
</wd:Type_Data>
</wd:Usage_Data>
</wd:Phone_Data>
You were close, but the way it was written your XPath was expecting the @wd:Formatted_Phone
attribute to be attached to the wd:Usage_Data
element. 您接近了,但是XPath的编写方式希望将
@wd:Formatted_Phone
属性附加到wd:Usage_Data
元素。 You want to select that element on the wd:Phone_Data
element and move the wd:Usage_data
inside of the predicate filter on the wd:Phone_Data
element. 要选择在该元素
wd:Phone_Data
元素和移动wd:Usage_data
谓语过滤器内的wd:Phone_Data
元素。
The following selects the @wd:Formatted_Phone
value of the wd:Phone_Data
element that has elements meeting your criteria (with additional predicates to target the wd:ID
elements with the specified @wd:type
value. 以下内容选择
wd:Phone_Data
元素的@wd:Formatted_Phone
值,该元素具有满足您的条件的元素(以及其他谓词,它们以指定的@wd:type
值作为目标wd:ID
元素。
wd:Worker_Data/wd:Personal_Data/wd:Contact_Data/
wd:Phone_Data[
wd:Phone_Device_Type_Reference/wd:ID[@wd:type='Phone_Device_Type_ID']='Cell # 1' and
wd:Usage_Data/wd:Type_Data/wd:Type_Reference/wd:ID[@wd:type='Communication_Usage_Type_ID']='WORK'
]/@wd:Formatted_Phone
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.