Question

I'm trying to translate my batch file calling the Saxon (version 8.9) into a XProc pipeline (Calabash). This is my batch call:

java -jar saxon8.jar -o out.xml in.xml style.xsl +config=config-file.cfg

The parameter config is defined in the stylesheet in this way:

<xsl:param name="config" as="document-node()"/>

The XProc part looks like this:

<p:load name="configLoad">
    <p:with-option name="href" select="'config-file.cfg'"/>
</p:load>
<p:xslt name="config">
    <p:input port="source">
        <p:document href="in.xml"/>
    </p:input>
    <p:input port="parameters">
        <p:inline>
            <c:param name="config">
                <p:pipe port="result" step="configLoad"/>
            </c:param>
        </p:inline>
    </p:input>
    <p:input port="stylesheet">
        <p:document href="style.xsl"/>
    </p:input>
</p:xslt>

The error message is this:

Required item type of value of variable $config is document-node(); supplied value has item type xs:string

I know the <p:exec> step but i don't want to use it, because the config-file shall be generated by other XSLT tranformations later. It shall also be reused by other XProc steps.

Is there a possibility to call the XSLT stylesheet with the correct parameter type? Thanks for your help!

Was it helpful?

Solution

Looks like you are out of luck with the current XProc standard. It states that parameters are name/value pairs where the data type of the values must be string of untypedAtomic. Don't ask me why..

http://www.w3.org/TR/xproc/#parameters

If you won't be composing the contents of your configuration dynamically, but are merely passing around contents of fixed files, you could pass through just a path to the appropriate config file, and use fn:doc() to read it from within the XSLT files.

I'd recommend against writing config files on the fly. Execution order within XProc may not be as sequentially as you might expect..

Alternative would be to pass through each config setting as a separate parameter, but then each setting would still have to comply to the flat parameter value type..

HTH!

OTHER TIPS

Provided that your config-file.cfg file is a well-formed XML, and you can use XSLT 2,
you can either use fn:doc(), as suggested by grtjn, or

  1. rewrite your XProc pipeline this way:
    <p:load name="configLoad">
        <p:with-option name="href" select="'config-file.cfg'"/>
    </p:load>
    <p:xslt name="config" version="2.0">
        <p:input port="source">
            <p:document href="in.xml"/>
            <p:pipe port="result" step="configLoad"/>
        </p:input>
        <p:input port="parameters">
            <p:empty/>
        </p:input>
        <p:input port="stylesheet">
            <p:document href="style.xsl"/>
        </p:input>
    </p:xslt>
    
  2. rewrite the relevant section of your stylesheet this way:
    <xsl:param name="config" as="document-node()" select="subsequence(collection(), 2)"/>
    

This lets you access the secondary input document from the xslt default collection.


Please do note that no intermediate <p:store> step is needed.

Furthermore, if you don't plan to reuse the config-file.cfg loaded document in other steps, you don't even need <p:load> inside your pipeline: you can simply use <p:document> inside the source input port, like this:

<p:input port="source">
    <p:document href="in.xml"/>
    <p:document href="config-file.cfg"/>
</p:input>

I have tested this in Oxygen XML, and it works.

BTW, all credit for this answer goes to Martin Honnen, see here: https://stackoverflow.com/a/60436209

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top