小编Mik*_*ike的帖子

XSLT选择包含特定子字符串的所有节点

我正在尝试编写一个XPath,它将选择包含特定单词的某些节点.在这种情况下,这个词是"洛克伍德".正确的答案是3.这两条路径都给了我3个.

count(//*[contains(./*,'Lockwood')])
count(BusinessLetter/*[contains(../*,'Lockwood')])
Run Code Online (Sandbox Code Playgroud)

但是当我尝试输出每个特定节点的文本时

//*[contains(./*,'Lockwood')][1]
//*[contains(./*,'Lockwood')][2]
//*[contains(./*,'Lockwood')][3]
Run Code Online (Sandbox Code Playgroud)

节点1最终包含所有文本,节点2和3为空白.

有人可以告诉我发生了什么或我做错了什么.

谢谢.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="XPathFunctions.xsl"?>
<BusinessLetter>
 <Head>
  <SendDate>November 29, 2005</SendDate>
  <Recipient>
   <Name Title="Mr.">
    <FirstName>Joshua</FirstName>
    <LastName>Lockwood</LastName>
   </Name>
   <Company>Lockwood &amp; Lockwood</Company>
   <Address>
    <Street>291 Broadway Ave.</Street>
    <City>New York</City>
    <State>NY</State>
    <Zip>10007</Zip>
    <Country>United States</Country>
   </Address>
  </Recipient>
 </Head>
 <Body>
  <List>
   <Heading>Along with this letter, I have enclosed the following items:</Heading>
   <ListItem>two original, execution copies of the Webucator Master Services Agreement</ListItem>
   <ListItem>two original, execution copies of the Webucator Premier Support for Developers Services Description between Lockwood …
Run Code Online (Sandbox Code Playgroud)

xslt xpath

5
推荐指数
1
解决办法
8312
查看次数

标签 统计

xpath ×1

xslt ×1