- From: Conal Tuohy <conal.tuohy@versi.edu.au>
- Date: Wed, 23 May 2012 11:00:22 +1000
- To: mozer <xmlizer@gmail.com>
- CC: XProc Dev <xproc-dev@w3.org>
- Message-ID: <4FBC36A6.1020205@versi.edu.au>
Yes I did get a satisfactory answer, thanks.
My mistake was to implement conditional processing using <p:choose> and
<p:when>. Instead I should have used <p:for-each>, and expressed the
conditional as a predicate in the <p:iteration-source>.
Using <p:choose> really only makes sense when choosing from a set (n>1)
of pipelines. If there's only 1 pipeline (to be either run or not run),
then <p:for-each> is better.
Thanks!
Conal
On 20/05/12 21:35, mozer wrote:
> 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
> <mailto: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"
> xmlns:fn="http://www.w3.org/2005/xpath-functions"
> xmlns:harvester="tag:conal.tuohy@versi.edu.au
> <mailto:tag%3Aconal.tuohy@versi.edu.au>,2012:oai-pmh"
> xmlns:oai="http://www.openarchives.org/OAI/2.0/"
> xmlns:tdar="http://www.tdar.org/namespace"
>
> >
>
> <harvester:list-records
> name="harvest"
> base-uri="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&')"/>
> <!-- 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 <tel:%2B61-466324297>
>
>
>
--
Conal Tuohy
eResearch Business Analyst
Victorian eResearch Strategic Initiative
+61-466324297
Received on Wednesday, 23 May 2012 01:01:18 UTC