XPATH帮助选择相同元素的多个实例

时间:2015-06-19 13:29:58

标签: xml xpath

我正在使用一个允许Xpath表达式获取表示和选择信息的工具...给出intput的xml (下面)文件,我试图确定要选择的Xpath和根据之前选择的标题和国家/地区返回多位艺术家

所以我拿国家:

 ROW:   //CATALOG/CD/COUNTRY[not(. = ../following-sibling;;CD/COUNTRY)]
 COLUMN: ----

然后我获取标题:

 ROW:   //CATALOG/CD[contains(./COUNTRY,'${cdcountry.value}')]
 COLUMN:  ./TITLE

我取艺术家:

  ROW:  //CATALOG/CD[contains(./TITLE,'${cdtitle.value}')]
  COLUMN: ./ARTIST

XML文件

<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
    <CD>
        <TITLE>Title1</TITLE>
        <ARTIST>Beatles</ARTIST>
        <COUNTRY>UK</COUNTRY>
        <COMPANY>Columbia</COMPANY>
        <PRICE>10.90</PRICE>
        <YEAR>1985</YEAR>
    </CD>
    <CD>
        <TITLE>Title2</TITLE>
        <ARTIST>Bonnie Tyler</ARTIST>
        <ARTIST>Taylor Swift</ARTIST>
        <ARTIST>Beastie Boys</ARTIST>
        <COUNTRY>US</COUNTRY>
        <COMPANY>CBS Records</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1988</YEAR>
    </CD>
    <CD>
        <TITLE>Title3</TITLE>
        <ARTIST>Eros Ramazzotti</ARTIST>
        <COUNTRY>IT</COUNTRY>
        <COMPANY>BMG</COMPANY>
        <PRICE>9.90</PRICE>
        <YEAR>1997</YEAR>
    </CD>
</CATALOG>

0 个答案:

没有答案