This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 3306 - XPath over a sequence of documents
Summary: XPath over a sequence of documents
Status: CLOSED FIXED
Alias: None
Product: XML Processing Model
Classification: Unclassified
Component: Pipeline language (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Norman Walsh
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-31 19:36 UTC by Norman Walsh
Modified: 2011-02-23 20:27 UTC (History)
1 user (show)

See Also:


Attachments

Description Norman Walsh 2006-05-31 19:36:31 UTC
What does it mean to evaluate an XPath expression over a sequence of documents?
Comment 1 Norman Walsh 2006-06-01 13:44:41 UTC
See http://lists.w3.org/Archives/Public/public-xml-processing-model-wg/2006May/0128.html

From: Jeni Tennison <jeni@jenitennison.com>

On this topic, I'd like to be able to do:

   <p:choose>
     <p:input name="input" ref="documents" />
     <p:when test="input contains one or more documents">
       ...
     </p:when>
     <p:otherwise>
       ...
     </p:otherwise>
   </p:choose>

If the input documents were assigned to a variable, this would be easy:

   <p:choose>
     <p:input name="input" select="$documents" />
     <p:when test="count($input) >= 1">
       ...
     </p:when>
     <p:otherwise>
       ...
     </p:otherwise>
   </p:choose>

I can't work out how you'd do it under the scheme of providing a context 
node for evaluating XPaths. I guess you'd have to use a separate 
component to do the counting:

   <p:step name="my:count">
     <p:with-input name="input" ref="documents" />
     <p:with-output name="output" label="count" />
   </p:step>
   <p:choose>
     <p:input name="input" ref="documents" />
     <p:param name="count" context="count" select="." />
     <p:when test="$count >= 1">
       ...
     </p:when>
     <p:otherwise>
       ...
     </p:otherwise>
   </p:choose>

Right?

Comment 2 Todd Gochenour 2010-09-29 19:38:06 UTC
This issue seems to be closest to what I'd like to propose.  I am looking for a standard way to dynamically evaluate an XPath string from a given context.  The evaluate() extension functions fail to accomplish this task. 

I recommend overloading the node() test function with a variant that takes a path parameter and returns the sequence represented by the parameter. For example, $c/node($path) returns the sequence of nodes relative to $c with the given path resolved.  Doesn't this solve the problem with a simple and intuitive enhancement to the XPath specification?  The change of evaluation to a template in XSL 2.1 doesn't solve the problem for XQuery.  The recommendation above does solve it.

With this enhancement, I can have one XML document contain one or more XPath strings used to define the serialization filtering done with the output when querying for another XML document.  Instead of the typical:

let $c = /documents[criteria='true']
return $c

...I can have

let $c = /documents[criteria='true']
let $fieldpaths = /form[@id='123']/group[type='grid']/field/@path
return element {name($c)}
{
   for $path in $fieldpaths
   return $c/node($path)
}

and this filters the output and thus improves the use of serialization bandwidth.