I'm having trouble populating multi-value cck fields using concat.

Example

<items>
  <item>
    <firstname>John</firstname>
    <lastname>Doe</lastname>
  </item>
  <item>
    <firstname>Max</firstname>
    <lastname>Mustermann</lastname>
  </item>
</items>

This will only populate the first field with "John Doe":

context = //item
field_fullname = concat(//firstname ' ', //lastname)

With out concat it works fine. This adds "John" to the first field and "Max" to the second:

context = //item
field_fullname = //firstname

Not sure if it is even supposed to work or pre-processing of the data is necessary to achieve this?

Using latest .dev

Comments

Countzero’s picture

I'm interested in this question too.

More generally, does the module allow the use of functions like "concat", "replace" and their siblings in the expressions ?

twistor’s picture

Assigned: Unassigned » twistor

Yes the dev version supports the use of concat, et al.

@andreas_jonsson,

Might this be what you're looking for?

context: //item
field_fullname: concat(firstname, ' ', lastname)
Countzero’s picture

Upgraded to dev version but can't get replace to function as of : http://www.w3.org/TR/xpath-functions/#func-replace.

Just trying a basic :

replace(GpsLatitudeExacte,",",".")

gives an unregistered function error.

twistor’s picture

PHP only supports XPath 1.0. Replace is in 2.0.

See http://www.w3.org/TR/xpath/

Countzero’s picture

OK, "translate" did the trick.

Thanks for your help.

twistor’s picture

Status: Active » Fixed

Marking this as fixed. Feel free to reopen.

shadybar’s picture

Having trouble here with a feed which imports profiles, and each profile can have different positions in various departments.

<profile>
  <id>1234567</id>
  <last>Smith</last>
  <first>Joe</last>
  <positions>
    <positioninfo>  
      <position>staff</position>  
      <rank>Director</rank>
      <dept>Services</dept>
    </positioninfo>
    <positioninfo>  
      <position>staff</position>  
      <rank>Junior</rank>
      <dept>Marketing</dept>
    </positioninfo>
  </positions>
</profile>

We need to import the position info into a multivalue cck field and concat the values as "position::rank::dept" in each field.

The following:

context://profile
position: concat(positions//positioninfo/position, '::', positions//positioninfo/rank, '::', positions//positioninfo/dept)

Works well to populate just one value in the CCK multivalue field, but not the others. Is there something else I can try?

Thank you for your help.

Countzero’s picture

Status: Fixed » Active

I have exactly the same problem : I discovered with amazement that the parser imports multiple values seemlessly and it 's really really great.

But unfortunately, I have to rewrite some image paths to avoid the curl error messages saying it cannot find the pictures.

As of now, I use concat("http://example.com/sites/default/files/mypath/", Photo) to build the correct path, but as stated by the previous poster, it prevents the multivalue feature from working.

Any help on this would be greatly appreciated.

Countzero’s picture

I tried to do something with Feeds Tamper but the curl error comes up before it applies its modifications, so it doesn't seem to be a solution.

Countzero’s picture

I solved my problem with some sed parsing of the original file, as I understand the implementation logic of the module is not suited for this kind of cases.

Just in case it could help some readers of this thread, here's how I rewrote the paths of my images :

cat original_file.xml | sed -e 's/>\(.*jpg\)/>public:\/\/new_path\/\1/' > new_file.xml

This bash code will append 'new_path' before any jpg filename in original_file.xml and save it to new_file.xml. This could be done in a bash script executed in cron.

The same logic could perhaps be used to structure the source file differently.

shadybar’s picture

Thank you for the posts, this is helpful.

What we ended up doing was we installed CCK 6.x-3.0-alpha3, which has the content multigroup module. Then we just created separate fields for each value, and let multigroup take care of the display.

twistor’s picture

Status: Active » Closed (fixed)
kenpeter’s picture

Issue summary: View changes

Based on this: http://stackoverflow.com/questions/24013046/xpath-how-to-run-concat-for-...

field_fullname: concat(firstname, ' ', lastname) will only return the first result. We need to use php to iternate. field_fullname: concat(firstname[n], ' ', lastname[n])