Project

Profile

Help

Patch #1420

closed

Add saxon:closure extension function

Added by Anonymous over 21 years ago. Updated over 12 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Internals
Sprint/Milestone:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Legacy ID:
sf-787809
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

SourceForge user: gschadow

Hi Michael, it worked! I could indeed add a saxon:closure

() extension function that will force it's argument

Expression to be lazily evaluated. It simply creates a

Closure from the first argument in the current

XPathContext.

In order to make it happen I had to make numerous little

additions, most of them to get the name saxon:closure

known. I used the saxon:expression extension function

as an example and did everything the way you did it for

saxon:expression.

The only real change that you may want to review is

that I made SequenceValue implement Item (simply by

adding one trivial little missing function implementation.

Also required was a little change in Value.asValue().

Attached is a ZIP file that contains the complete diff

that should take care of every change needed. It's

against 7.6 though but the diff has not much context so

I don't think much would be rejected.

Also in the ZIP file is a little test case (to invoke as a

transform over any XML input). The test-case requires a

Java extension thingie with a little side-effect, because

that's my whole point.

The point that the test illustrates is how side-effects

can be carried out with lazy evaluation ONLY if the value

is actually referenced. The real example is a database

insert that should only be done for parent-records that

have dependent children. If you run the example without

the closure() function it's output is:

next 1 for insert a

next 2 for insert b parent 1

next 3 for insert c parent 1

next 4 for insert d

next 5 for insert e

next 6 for insert f parent 5

  <child id="2" parentId="1" name="b"/>

  <child id="3" parentId="1" name="c"/>
  <child id="6" parentId="5" name="f"/>

which is bad because it inserted "next 4 for indsert d" for

the parent named "d" that had no children. Once you

apply the patch and use the closure() function the

output is correctly:

next 1 for insert a

next 2 for insert b parent 1

next 3 for insert c parent 1

next 4 for insert e

next 5 for insert f parent 4

  <child id="2" parentId="1" name="b"/>

  <child id="3" parentId="1" name="c"/>
  <child id="5" parentId="4" name="f"/>

Files

saxon-closure.zip (9.56 KB) saxon-closure.zip Anonymous, 2003-08-13 04:25
closure.diff (9.56 KB) closure.diff Anonymous, 2003-08-13 21:26

Please register to edit this issue

Also available in: Atom PDF