0

I'm working on an import from an RSS feed that includes two types of XML <category> elements:

  • Subject Areas, e.g. <category>Economics | Social and Behavioral Sciences</category>
  • Keywords, e.g. <category domain="keywords">immigration, emigration, immigrants, international migration, poverty, immigration enforcement, asylum policy</category>

I want to import the Keywords as their own taxonomy field. I can write the YAML as follows, but it predictably imports both Keywords and Subject Areas:

source:
  fields:
    -
      name: keywords
      label: Keywords
      selector: 'category'
process:
  field_keywords:
    -
      plugin: explode
      delimiter: ', '
      source: keywords
    -
      plugin: entity_generate

How do I adjust the selector so it only pulls from the <category> element that includes the domain="keywords" attribute?

0

I figured this out with the help of an XPATH cheatsheet that shows how selectors I might have written to target HTML would transfer to XPATH values.

To only pull <category domain="keywords"> items, I can use category[@domain="keywords"] as my selector. The other set of <category> items don't have a domain attribute, so I pulled them separately using the selector category[not(@domain)].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.