I'd like to use some Xpath functions, but I can't seem to make it work ..

My context is : /programs/program
With this, I can easily access my title, date, etc .. fields, which are nodes from a program

Now I want to combine 2 strings, so I tried the concat function, by typing :
concat(from_date, to_date) but it doesnt seem to work
I've also tried :
- concat(/programs/program/from_date, /programs/program/to_date)
- fn:concat(from_date, to_date)
But to no avail.

Is it because the context is put before that function ? Or am I using the wrong syntax ?
I've tried other functions, but I can't seem to get any of them to work

CommentFileSizeAuthor
#2 xml.png28.79 KBcopyhold
#2 settings.png7.46 KBcopyhold

Comments

twistor’s picture

Assigned: Unassigned » twistor
Category: support » bug

The context shouldn't affect anything. Can you give me a specific example?

copyhold’s picture

StatusFileSize
new7.46 KB
new28.79 KB

subscribe
Does XPath functions work?

netw3rker’s picture

I'm running into a similar problem i cant get concat to work at all. here's an xml excerpt:

...
<area area_id="8" countrycode="AFG" name="Afghanistan"/>
<area area_id="19" countrycode="AUS" name="Australia"/>
<area area_id="23" countrycode="BHR" name="Bahrain"/>
<area area_id="24" countrycode="BAN" name="Bangladesh"/>
<area area_id="31" countrycode="BHU" name="Bhutan"/>
...

settings that don't work:
context = //area
guid = @area_id
title = concat(@countrycode, ' - ', @name)

settings that do work:
context = //area
guid = @area_id
title = @name

does the xpath function for concat work with this module or are only paths to data allowed? also note that it does create all of the nodes, and does not throw an error, it just leaves the title blank (in this case).

This is sort of an important thing because when importing many peices of content that might have the same id# for the guid, it will help to be able to concat something that will make it more unique.

Andyj2106’s picture

Subscribing...

I also can't get concat to work and my example is very similar to the above. All other fields in the context are accessible and being used in creating the node, including the two fields that are being concatted. As I use the concat in the GUID, I get one node created, with 3 revisions, instead of 3 nodes with 1 revision each, because I have 3 items in the XML that should be unique based on the concatenation of 2 pieces of data.

kyen99’s picture

Same problem here. And without xpath functions, I can't even see a way to use the variable substitution, since simply putting a variable in the mapping field results in an error from trying to parse the value of the variable. It would seem that to use a variable you would need to do: string($variable), but this doesn't work either.

twistor’s picture

The variable needs to be in quotes, "$variable". This probably isn't correct behavior, it should probably be quoted beforehand, if it's a string.

twistor’s picture

I've been all around the internet, trying to find info about this problem. The only only information I have been able to find was on an IBM site. "SimpleXML only supports XPath location paths and unions of location paths. It does not support XPath expressions that do not return node-sets, such as count(//para) or contains(title)." This is probably a good time to start thinking about a switch to the dom from SimpleXML.

As a workaround, although not ideal, concat and various string emulations can be emulated with feeds_tamper.

twistor’s picture

Category: bug » feature

Ok, so I rewrote the parsing to use DOMXPath instead of SimpleXML. It seems to be working ok, but I'll need people to tests it out before I release it.

Functions are working as expected!

twistor’s picture

twistor’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

zazinteractive’s picture

I think the latest dev broke this feature again

EDIT: My bad. I upgraded to the stable release by accident, not the dev version. Sorry about that.

john bickar’s picture

Status: Closed (fixed) » Active

I have been testing this (the concat() function) with the -dev version and it works great.

Any chance of rolling a stable release with this functionality?

Thanks!

twistor’s picture

Status: Active » Closed (fixed)

On their way.

jjmackow’s picture

Is there any support for the date functions? I'm trying queries with year-from-dateTime and similar date functions but getting an error within the
admin/build/feeds/edit/{NAME_OF_MY_IMPORTER]/settings/FeedsXPathParserHTML screen of "Unregistered function".

I've got a question though?

considering line 11 of FeedsXPathParserDOMXPath.inc
class FeedsXPathParserDOMXPath extends DOMXPath {...

and looking at DOMXPath in PHP, is it possible to use PHP's own date functions?

http://www.php.net/manual/en/domxpath.registerphpfunctions.php