RE: Can a pipeline 'call' itself?

Tomos,

You can certainly do recursion in XProc pipelines. The example pipeline below was used to test a 'paged' Atom feed. The step of type 'test:get-page' tests, using a p:choose, for the presence of a 'next' link in the feed and keeps calling itself until there is no 'next' link at which point it exits. I haven't run it recently so I can't say it'll work straight-off but the principle is valid. How that exactly fits what you're trying to do I can't say but it might help.


Regards

Philip


<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step 
		xmlns:as="http://atomserver.org/namespaces/1.0/"
		xmlns:atom="http://www.w3.org/2005/Atom"
		xmlns:c="http://www.w3.org/ns/xproc-step"
		xmlns:cx="http://xmlcalabash.com/ns/extensions"
		xmlns:os="http://a9.com/-/spec/opensearch/1.1/"
		xmlns:p="http://www.w3.org/ns/xproc"
		xmlns:pxp="http://exproc.org/proposed/steps"
		xmlns:test="http://www.test.foo.co.uk/"
		xmlns:xs="http://www.w3.org/2001/XMLSchema"
		xml:base="../../"
		exclude-inline-prefixes="atom c cx p pxp test xs"
		name="test"
		version="1.0">
	
	<p:serialization port="result" indent="true" omit-xml-declaration="false" 
			method="xml" encoding="utf-8" media-type="application/xml"/>
	
	<p:input port="source" sequence="false">
		<p:inline>
			<test:results/>
		</p:inline>
	</p:input>
	<p:output port="result" sequence="false"/>
	
	<p:import href="../lib/library-1.0.xpl"/>
	<p:import href="lib/core.xpl"/>
	
	<p:declare-step name="feed-page" type="test:get-page">
		<p:input port="source" sequence="false"/>
		<p:output port="result" sequence="false"/>
		
		<p:option name="href"/>
		<p:option name="entries-per-page"/>
		<p:option name="index"/>
		
		<p:load name="get-feed">
			<p:with-option name="href" select="concat($href, '?max-results=', $entries-per-page ,'&amp;start-index=', $index)"/>
		</p:load>
		
		<p:insert name="insert-page" match="/test:results" position="last-child">
			<p:input port="source">
				<p:pipe step="feed-page" port="source"/>
			</p:input>
			<p:input port="insertion">
				<p:pipe step="get-feed" port="result"/>
			</p:input>
		</p:insert>
		
		<cx:message>
			<p:with-option name="message" select="concat('[test:get-page] ', /test:results/atom:feed[last()]/atom:link[@rel = 'self']/@href)"/>
		</cx:message>
		
		<p:choose>
			<p:when test="/test:results/atom:feed[last()]/atom:link[@rel = 'next']">
				<test:get-page>
					<p:with-option name="href" select="$href"/>
					<p:with-option name="entries-per-page" select="$entries-per-page"/>
					<p:with-option name="index" select="/test:results/atom:feed[last()]/as:endIndex"/>
				</test:get-page>
			</p:when>
			<p:otherwise>
				<p:identity/>
			</p:otherwise>
		</p:choose>
	</p:declare-step>
	
	<test:get-page href="http://192.168.192.10:8080/atomserver/v1/test/atom-6/" entries-per-page="4" index="0"/>
<!--	<test:get-page href="https://api.test.foo.co.uk/atomstore/v1/pets/dogs/" entries-per-page="4" index="0"/>-->
	
	<p:validate-with-schematron name="validate">
		<p:input port="source"/>
		<p:input port="parameters">
			<p:empty/>
		</p:input>
		<p:input port="schema">
			<p:document href="atom-6/schema/paged-feeds.sch"/>
		</p:input>
		<p:log port="result" href="logs/atom-6.xml"/>
	</p:validate-with-schematron>
	
	<p:identity>
		<p:input port="source">
			<p:pipe step="validate" port="report"/>
		</p:input>
	</p:identity>
</p:declare-step>



-----Original Message-----
From: xproc-dev-request@w3.org [mailto:xproc-dev-request@w3.org] On Behalf Of HILLMAN, Tomos
Sent: 27 July, 2010 6:08 PM
To: xproc-dev@w3.org
Subject: Can a pipeline 'call' itself?

Hi List,

I'm tinkering with some chunking scripts (again!), and would appreciate some advice on how to approach a problem.

Essentially our (document based) data has some 'floating' structures which are called in at relevant points in the XML using processing instructions (please don't suggest alternative data models; that's well outside the scope of the problem!).  These are often stored elsewhere in the document compared to the XML we might wish to extract into a 'chunk'.  Fairly straightforward so far; I can successfully pull floats into the chunk from the original complete document based on references within that chunk.

The issue is that these floating structures may themselves refer to other floating structures; therefore some form of recursion (and testing) is required.  What is the best way of approaching this?  I assume that it's not XProc's 'way' to have a procedural 'do.. until' structure - is the alternative to build a timeline that 'calls' itself?

Thanks in advance,

Tom

Oxford University Press (UK) Disclaimer

This message is confidential. You should not copy it or disclose its contents to anyone. You may use and apply the information for the intended purpose only. OUP does not accept legal responsibility for the contents of this message. Any views or opinions presented are those of the author only and not of OUP. If this email has come to you in error, please delete it, along with any attachments. Please note that OUP may intercept incoming and outgoing email communications.

Received on Tuesday, 27 July 2010 19:41:16 UTC