xpath - XProc - How to repeat a subpipeline for a specific number of times -
i'd repeat xproc subpipeline given number of times. (in usecase subpipeline consists of exec-step, runs latex on created .tex-file)
a simplified version of code looks following, gives no result far:
<p:declare-step version="1.0" xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step"> <p:option name="latex-exec" select="'uri/latex'"/> <p:option name="latex-repeat" select="3"/> <p:option name="tmp-path" select="'uri/tmp/'"/> <p:option name="tmp-file" select="'tmp'"/> <!-- pre-processing --> <p:for-each> <p:iteration-source select="(1 $latex-repeat)"/> <p:exec result-is-xml="false"> <p:with-option name="command" select="$latex-exec"/> <p:with-option name="args" select="string-join(('-interaction=nonstopmode','-halt-on-error','-output-format=pdf',concat('-output-directory=',$tmp-path),concat($tmp-path,$tmp-file,'.tex')),' ')"/> <p:input port="source"> <p:empty/> </p:input> </p:exec> </p:for-each> i don't know if issue xpath-2.0 expression in p:iteration-source element. however, following works , gives correct result "message: 3":
<cx:message> <p:with-option name="message" select="count((1 $latex-repeat))"/> <p:input port="source"> <p:empty/> </p:input> </cx:message> my exec-step tested outside for-each loop , works. working calabash under oxygen 16.0.
the problem approach can iterate on xml documents in xproc 1.0. since select expression in p:iteration-source produces sequence of numbers, not documents, pipeline fail dynamic error (most err:xd0001: dynamic error if non-xml resource produced on step output or arrives on step input.)
(the reason why example cx:message works p:with-option construct binds value option , result of select xpath expression treated xs:untypedatomic.)
to loop n number of times, have use recursion, in following example (untested should idea):
<p:declare-step version="1.0" xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:my="http://example.org/latex-process" type="my:latex-process"> <p:option name="latex-exec" select="'uri/latex'"/> <p:option name="latex-repeat" select="3"/> <p:option name="tmp-path" select="'uri/tmp/'"/> <p:option name="tmp-file" select="'tmp'"/> <p:choose> <p:when test="$latex-repeat = 0"> <p:sink> <p:input port="source"> <p:empty/> </p:input> </p:sink> </p:when> <p:otherwise> <p:exec result-is-xml="false"> <p:with-option name="command" select="$latex-exec"/> <p:with-option name="args" select="string-join(('-interaction=nonstopmode','-halt-on-error','-output-format=pdf',concat('-output-directory=',$tmp-path),concat($tmp-path,$tmp-file,'.tex')),' ')"/> <p:input port="source"> <p:empty/> </p:input> </p:exec> <my:latex-exec> <p:with-option name="latex-exec" select="$latex-exec"/> <p:with-option name="latex-repeat" select="$latex-repeat - 1"/> <p:with-option name="tmp-path" select="$tmp-path"/> <p:with-option name="tmp-file" select="$tmp-file"/> </my:latex-exec> </p:otherwise> </p:choose> </p:declare-step>
Comments
Post a Comment