对于以下xml,xpath的内容是什么:
<ContactTypeCode>
<ContactAddress>
<ContactDetails>
<ContactDetail>
<ContactTypeCode>EMAIL</ContactTypeCode>
<ContactTypeText>Email Address</ContactTypeText>
<ContactAddress>hpinfo@acme.co.uk</ContactAddress>
</ContactDetail>
<ContactDetail>
<ContactTypeCode>FPPRNO</ContactTypeCode>
<ContactTypeText>Fit and Proper Person Reg No.</ContactTypeText>
<ContactAddress>AGE146</ContactAddress>
</ContactDetail>
<ContactDetail>
<ContactTypeCode>PHONE</ContactTypeCode>
<ContactTypeText>Phone</ContactTypeText>
<ContactAddress>084892747291</ContactAddress>
</ContactDetail>
</ContactDetails>
答案 0 :(得分:3)
我相信不按字母顺序执行操作会更简单:
<xsl:value-of select="/ContactDetails/ContactDetail[ContactTypeCode='FPPRNO']/ContactAddress"/>
这假设您要使用绝对路径。根据您的上下文,您可以使用当前节点的相对路径,使其更短。
P.S。当明确指定路径时,最好避免使用//
快捷方式。
答案 1 :(得分:1)
尝试以下表达式:
//ContactTypeCode[text()="FPPRNO"]/following-sibling::ContactAddress/text()