0

XProc サブパイプラインを指定された回数繰り返したいと思います。(私のユースケースでは、サブパイプラインは、以前に作成された .tex ファイルに対して LaTeX を実行する exec-step で構成されています)

私のコードの簡略化されたバージョンは次のようになりますが、これまでのところ結果はありません。

<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 to $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>

p:iteration-source 要素の XPath-2.0 式の問題かどうかはわかりません。ただし、以下は機能し、正しい結果 "Message: 3" が得られます。

<cx:message>
    <p:with-option name="message" select="count((1 to $latex-repeat))"/>
    <p:input port="source">
        <p:empty/>
    </p:input>
</cx:message>

私の exec-step は for-each ループの外でテストされ、機能します。Oxygen 16.0でCalabashを使用しています。

4

2 に答える 2

0

Vojtěch Toman が述べたように、p:for-each ループはアトミック値を反復できません [ XD0016 ]。この制限は、同等の XSLT 2.0 ループには適用されないため、独自の p:xslt ステップを定義して、必要な反復回数に従って一連の XML ノードを作成できます。次に、このシーケンスを ap:for-each の入力として使用できます。

イテレータのステップは次のようになります。

<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/iterate"
    type="my:iterator">

    <p:option name="iterate" required="true"/>

    <p:input port="source"/>
    <p:output port="result" sequence="true"/>

    <p:xslt name="iterator" template-name="iterator">
        <p:with-param name="iterator" select="$iterate"/>
        <p:input port="stylesheet">
            <p:inline>
                <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
                    <xsl:param name="iterator"/>
                    <xsl:template name="iterator">
                        <xsl:for-each select="(1 to xs:integer($iterator))">
                            <xsl:result-document href="{position()}">
                                <iterate/>
                            </xsl:result-document>
                        </xsl:for-each>
                    </xsl:template>
                </xsl:stylesheet>
            </p:inline>
        </p:input>
        <p:input port="source">
            <p:empty/>
        </p:input>
    </p:xslt>

    <p:sink/>

    <p:identity>
        <p:input port="source">
            <p:pipe port="secondary" step="iterator"/>
        </p:input>
    </p:identity>

</p:declare-step>

新しい反復子ステップを使用した例は次のようになります。

<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/iterate">

    <p:import href="iterate.xpl"/>

    <!-- pre-processing -->    

    <my:iterator>
        <p:with-option name="iterate" select="3"/>
    </my:iterator>
    <p:for-each>

        <!-- sub-pipeline -->

    </p:for-each>

</p:declare-step>
于 2015-08-28T09:13:26.483 に答える
0

あなたのアプローチの問題は、XProc 1.0 で XML ドキュメントを反復処理することしかできないことです。あなたのselectp:iteration-sourceはドキュメントではなく一連の数字を生成するため、パイプラインは動的エラーで失敗します (おそらくerr:XD0001: It is a dynamic error if a non-XML resource is produced on a step output or arrives on a step input.)

cx:message( の例が機能する理由は、p:with-option構造が値をオプションにバインドし、selectXPath 式の結果が として扱われるためxs:untypedAtomicです。)

n回ループするには、次の例のように再帰を使用する必要があります (テストされていませんが、アイデアを得る必要があります)。

<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>
于 2015-08-25T11:26:03.913 に答える