I am attempting to import multiple values into a multiple value cck field. It works however it is grabbing every matching element within the page I am parsing and ignoring the base query.

Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>...</head>
<body>
<div id="page" class="container-16 clear-block">
  <div id="main" class="column grid-12 push-4">
    <div id="main-inner">
      <div>
        <div>
          <div>
            <ul id="my-list">
              <li>
                <div class="views-field-field-screenshot-fid">
                  <div class="field-item field-item-0">
                    <a href="http://mysite.com/someimage0.png" class="screenshot"><img src="http://mysite.com/someimagethumb0.png" /></a>
                  </div>
                  <div class="field-item field-item-1">
                    <a href="http://mysite.com/someimage1.png" class="screenshot"><img src="http://mysite.com/someimagethumb1.png" /></a>
                  </div>
                </div>
              </li>
              <li>
                <div class="views-field-field-screenshot-fid">
                  <div class="field-item field-item-0">
                    <a href="http://mysite.com/someimage3.png" class="screenshot"><img src="http://mysite.com/someimagethumb3.png" /></a>
                  </div>
                  <div class="field-item field-item-1">
                    <a href="http://mysite.com/someimage4.png" class="screenshot"><img src="http://mysite.com/someimagethumb4.png" /></a>
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
...
</body>
</html>

From the above I am doing:
Context:

//ul[@id='my-list']/li

field_screenshot:

//a[contains(@class, 'screenshot')]/@href

End result is that I get two nodes which contain all four target href attributes, rather than one node with the first two href attributes and a second node with the second two.

Comments

nicholas.alipaz’s picture

Status: Active » Postponed (maintainer needs more info)

hhmmm, perhaps my xpath is off. just noticed some other things. Leave this alone for now and I will research a little more.

nicholas.alipaz’s picture

Title: Multiple values not respecting Context query » '//' at beginning of query ignores Context query

Ok, I guess it works correctly, however I am not sure if it is supposed to do what it does.

If I do a '//' at the beginning of my query then it bypasses the Context query from what I can tell. Is this actually how it should work?

Context:

.//*[@id='my-list']/li

field_screenshot:

//a[contains(@class, 'screenshot')]/@href

returns all href values on the entire page rather than just the two within the context.

nicholas.alipaz’s picture

Status: Postponed (maintainer needs more info) » Active
twistor’s picture

Component: Code » Documentation
Assigned: Unassigned » mitchell

It works as it's supposed to. It used to behave like you're expecting, but that was actually a bug. The documentation probably needs to be updated somewhere. One advantage is that you can access things outside the context if you need to.

See #900632: Grab value from outside the context section of XML... At all possible?.

One way to solve your problem:

  • Context:
    //ul[@id='my-list']/li
    
  • field_screenshot (notice the dot):
    .//a[contains(@class, 'screenshot')]/@href
    
mitchell’s picture

Assigned: mitchell » twistor
nicholas.alipaz’s picture

Title: '//' at beginning of query ignores Context query » Document '//' and other syntax for this module a little better
Category: bug » support
Status: Active » Needs work

ok then just an update on the docs should likely do it. Thanks for the clarification. Great module!

nicholas.alipaz’s picture

Category: support » task

task makes more sense here

twistor’s picture

Assigned: twistor » mitchell

humph

twistor’s picture

Status: Needs work » Fixed

The docs now reflect this.

Status: Fixed » Closed (fixed)

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