Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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
Comment #1
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedhhmmm, perhaps my xpath is off. just noticed some other things. Leave this alone for now and I will research a little more.
Comment #2
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedOk, 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:
field_screenshot:
returns all href values on the entire page rather than just the two within the context.
Comment #3
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedComment #4
twistor CreditAttribution: twistor commentedIt 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:
Comment #5
mitchell CreditAttribution: mitchell commentedComment #6
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedok then just an update on the docs should likely do it. Thanks for the clarification. Great module!
Comment #7
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedtask makes more sense here
Comment #8
twistor CreditAttribution: twistor commentedhumph
Comment #9
twistor CreditAttribution: twistor commentedThe docs now reflect this.