Project

General

Profile

Actions

Feature #5013

closed

Support every XPath functions in all contexts

Added by Reynaud Sylvain about 11 years ago. Updated about 11 years ago.

Status:
Resolved
Priority:
High
Assigned To:
Category:
Engine
Target version:
Start date:
09/12/2013
Due date:
% Done:

100%

Estimated time:

Description

Refactoring steps:
1) develop java class to invoke <processor> for all SELECTED and DESCENDANT_OF_SELECT events.
2) support new syntax:

  • develop XSL to translate new syntax to current syntax (for pre-processing).
  • develop XSL to translate current syntax to new syntax (for lavoisier-update-config.sh).

3) support Lavoisier XPath functions in PiXTL short notation (modify XSL to translate PiXTL short notation to new syntax).
4) support new syntax hidden parameters

  • modify XSL to generate hidden parameters.
  • instanciate plug-in from new syntax.

5) refactoring: move AbstractSAXPathProcessor to engine:

  • modify adaptor interfaces.
  • modify engine.
Language modifications:
  • replace parameter "nodes" with attribute @match.
  • replace parameter "namespaces" with xmlns:ns.
  • replace parameters "variables" and "xml_variables" with <variable xml="true|FALSE"/>.
  • support all XPath functions in both context, except function matched().

Pre-processing steps:
1) add parameter types from processors:

  • constant: never evaluated.
  • relative path: potentially evaluated for each node.
  • expression: evaluated for each selected node (text() is converted to 'constant', and @eval is converted to $variable).

2) convert XPath to XML tree <eval>.
3) optimize:

  • move the XPath functions that have no descendant::RelativeLocationPath (nor path relative to function matched()) to variables.
  • add attribute @onEvents to <parameter>.
  • convert XML tree <eval> to XPath @eval.

Example with actual notation:

<processor type="ReplaceProcessor">
    <parameter name="namespaces">
        <entry key="e">http://software.in2p3.fr/lavoisier/entries.xsd</entry>
    </parameter>
    <parameter name="variables">
        <entry key="prefix" eval="path('prefix')"/>
    </parameter>
    <parameter name="xml_variables">
        <entry key="xml" eval="request()"/>
    </parameter>
    <parameter name="nodes">/e:entries/e:entry[@key &lt; $xml/@value]</parameter>
    <parameter name="node_prefix" eval="property('ns.entries')"/>
    <parameter name="node_name">concat(path('prefix'),'-suffix')</parameter>
    <parameter name="node_name_as_xpath">true</parameter>
    <parameter name="node_value">'1'</parameter>
</processor>

The same example with target notation:

<processor type="ReplaceProcessor" xmlns:e="http://software.in2p3.fr/lavoisier/entries.xsd" 
           match="/e:entries/e:entry[@key &lt; request()/@value]">
    <parameter name="node_prefix" eval="property('ns.entries')"/>
    <parameter name="node_name" eval="concat(path('prefix'),'-suffix')"/>
    <parameter name="node_value">1</parameter>
</processor>

The same example optimized by Lavoisier:

<processor type="ReplaceProcessor" xmlns:e="http://software.in2p3.fr/lavoisier/entries.xsd" 
           match="/e:entries/e:entry[@key &lt; $_match1]">
    <variable name="_match1" eval="request()/@value"/>
    <variable name="_node_name1" eval="concat(path('prefix'),'-suffix')"/>
    <parameter name="node_prefix" eval="property('ns.entries')"/>
    <parameter name="node_name">$_node_name1</parameter>
    <parameter name="node_value">'1'</parameter>
</processor>

Example XPath expression:
choose(
    $a != @id,
    view('v', arguments() | entry('k', post()/*/*[@id=$a])),
    view('v', arguments() | entry('k', post()/*/*[@id=current()/*/*[@name=property('name')]/@id]))
)

Then the following expressions must be evaluated for each selected event:
  • @id
  • current()/*/*[@name=$_4]/@id
Main benefits:
  • less verbose.
  • same XPath functions in both contexts.
  • any parameter can be evaluated as an XPath expression.
Actions

Also available in: Atom PDF