2012-09-02 108 views
2

我在Drupal 7 cms中使用了feed導入模塊,它接受xpath指令來映射導入數據。是否有可能只選擇部分原子值或用xpath分解它? 例如:Xpath選擇功能?

<book> 
... 
<categories>1,4,88</categories> 
... 
</book> 

是否有可能與XPath語句只得到1或4或88分開?

回答

2

可以使用substring-before()substring-after()功能:

  • 要選擇1:substring-before(/book/categories, ',')
  • 要選擇4:substring-before(substring-after(/book/categories, ','), ',')
  • 要選擇88:substring-after(substring-after(/book/categories, ','), ',')

在XPath 2.0你可以使用tokenize()功能:

  • 要選擇1:tokenize(/book/categories, ',')[1]
  • 選擇4:tokenize(/book/categories, ',')[2]
  • 要選擇88:tokenize(/book/categories, ',')[3]
1

或者,使用XPath 2.0,可以通過訪問N th組件:

tokenize(/*/categories[1], ',')[$pN] 

其中$pN是所需的基於1的索引。