Passing document href as an option in XProc

65 Views Asked by At

I have an XProc script that currently hardcodes document hrefs like this:

<p:xslt>
    <p:input port="source"/>
    <p:input port="stylesheet">
        <p:document href="/path/to/stylesheet.xsl"/>
    </p:input>
</p:xslt>

I would like to pass /path/to/stylesheet.xsl as an option to the xproc script, so in my declare-step I put:

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

but I still can't figure out how to replace the hardcoded href in p:document with the option value.

I'll be most grateful for your help.

1

There are 1 best solutions below

1
On

Here's what eventually worked for me:

  1. Create a step to load the document with the option passed to it:

    <p:load name="getStylesheetSource">
      <p:with-option name="href" select="$stylePath" /> 
    </p:load>
    
  2. Then, in the XSLT step, pipe the loaded stylesheet

    <p:xslt name="transform">
        <p:input port="source">
           <!-- etc. -->  
        </p:input>
        <p:input port="stylesheet">
           <p:pipe step="getStylesheetSource" port="result" /> 
        </p:input>
    </p:xslt>
    

With this setup, one can pass the stylePath option when invoking the XProc script without having to hard code the path.