Re: inelegant but working pipeline seeks elegance

Hi Conal,

Since you truncated the last result, it's not clear to me if you found the
answer you were looking for at the time

Xmlizer

2012/3/12 Conal Tuohy <conal.tuohy@versi.edu.au>

> Embarrassing isn't it, when you ask for help and then immediately see a
> better alternative yourself?
>
> I managed to remove the p:choose[@name='whether-to-**save-record'] within
> the p:viewport moving the conditional into a predicate in the p:viewport's
> select statement (see below).
>
> I guess I could also convert the resumptionToken handling to use a
> p:viewport rather than a p:choose. The sub-pipeline of the p:viewport would
> run either once (if there were a resumptionToken) or not at all.
>
> Perhaps the rule of thumb I'm looking for is:
>
> To implement a simple "if", always use a p:viewport rather than a p:choose
> (because the  p:otherwise would be a pain).
>
>  <?xml version="1.0"?>
>> <p:declare-step
>>    version="1.0"
>>    xmlns:p="http://www.w3.org/ns/**xproc <http://www.w3.org/ns/xproc>"
>>    xmlns:fn="http://www.w3.org/**2005/xpath-functions<http://www.w3.org/2005/xpath-functions>
>> "
>>    xmlns:harvester="tag:conal.**tuohy@versi.edu.au<tag%3Aconal.tuohy@versi.edu.au>
>> ,2012:oai-**pmh"
>>    xmlns:oai="http://www.**openarchives.org/OAI/2.0/<http://www.openarchives.org/OAI/2.0/>
>> "
>>    xmlns:tdar="http://www.tdar.**org/namespace<http://www.tdar.org/namespace>
>> "
>>
>> >
>>
>> <harvester:list-records
>>        name="harvest"
>>        base-uri="http://ahad.edu.au/**oai-pmh/oai<http://ahad.edu.au/oai-pmh/oai>
>> "
>>        base-storage-uri="/tmp/**harvest/"
>>        metadata-prefix="tdar"/>
>>
>> <p:declare-step type="harvester:list-records" name="list-records">
>> <p:option name="base-uri" required="true"/>
>> <p:option name="base-storage-uri" required="true"/>
>> <p:option name="metadata-prefix"/>
>> <p:option name="resumption-token"/>
>> <p:variable name="uri" select="concat($base-uri,
>> '?verb=ListRecords&amp;')"/>
>> <!-- query the OAI-PMH server -->
>> <p:choose name="resumption-token-or-**metadata-prefix">
>> <p:when test="p:value-available('**resumption-token')">
>> <p:load name="query-with-resumption-**token">
>> <p:with-option name="href" select="concat($uri, 'resumptionToken=',
>> $resumption-token)"/>
>> </p:load>
>> </p:when>
>> <p:otherwise>
>> <p:load name="query-with-metadata-**prefix">
>> <p:with-option name="href" select="concat($uri, 'metadataPrefix=',
>> $metadata-prefix)"/>
>> </p:load>
>> </p:otherwise>
>> </p:choose>
>> <p:identity name="query-results"/>
>> <p:viewport name="record" match="oai:OAI-PMH/oai:**
>> ListRecords/oai:record[oai:**metadata[tdar:dataset | tdar:project |
>> tdar:person | tdar:institution | tdar:image | tdar:sensoryData]]">
>>
>> <!-- double-encode the record identifier so as to produce URI-encoded
>> file name -->
>> <p:variable name="file-name" select="concat(fn:encode-for-**
>> uri(fn:encode-for-uri(/oai:**record/oai:header/oai:**identifier)),
>> '.xml')"/>
>> <!-- save the record -->
>> <p:store name="save-record" indent="true">
>> <p:input port="source" select="oai:record/oai:**metadata/*"/>
>> <p:with-option name="href" select="concat($base-storage-**uri,
>> $file-name)"/>
>> </p:store>
>> <p:identity>
>> <p:input port="source">
>> <p:pipe step="save-record" port="result"/>
>> </p:input>
>> </p:identity>
>> </p:viewport>
>>
>> <!-- query again (recursively) if a resumptionToken was returned in the
>> query results -->
>> <p:choose name="whether-to-resume-query"**>
>> <p:variable name="resumption-token-**returned" select="/oai:OAI-PMH/oai:*
>> *ListRecords/oai:**resumptionToken"/>
>> <p:when test="normalize-space($**resumption-token-returned)">
>> <harvester:list-records>
>> <p:with-option name="base-uri" select="$base-uri"/>
>> <p:with-option name="base-storage-uri" select="$base-storage-uri"/>
>> <p:with-option name="resumption-token" select="$resumption-token-**
>> returned"/>
>> </harvester:list-records>
>> </p:when>
>> <p:otherwise>
>> <!-- no resumption token (or empty resumption token) returned; nothing to
>> do -->
>> <p:identity name="dummy1"/>
>> <p:sink name="dummy2"/>
>> </p:otherwise>
>> </p:choose>
>>
>> </p:declare-step>
>>
>> </p:declare-step>
>>
>
>
>
> --
> Conal Tuohy
> eResearch Business Analyst
> Victorian eResearch Strategic Initiative
> +61-466324297
>
>
>

Received on Sunday, 20 May 2012 11:36:09 UTC