Archive for May, 2012

XPath Everywhere

May 17, 2012

My head is still reeling from this. Today I looked at a question on the Pipes message boards that included a link to the user’s (Tikkie) pipe –

I noticed that the Rename module was using Xpath expressions. "Well that won’t work" I thought. But actually it did! Using XPath expressions to define an element can greatly simplify that definition. For instance, the traditional way of defining the first element in the Rename module would be ‘item.div.div.div.0.div.div.1.div.p’ (it was an effort working that out). Compare that to ‘item.//*[@id="more-description"]/p’.

Here’s a link to my copy of that pipe with a few more uses of Xpath to define elements in other modules:

I’ve contacted the Pipes team about this. They’re hoping that this can be a supported feature.

Update: This use of XPath expressions is supported. I quote from Paul Donnelly ‘it’s baked into Pipes’.

Update: We can use ‘//*[@id="more-description"]/p’ instead of ”item.//*[@id="more-description"]/p’ (thanks to Paul Donnelly for this tip).