How to connect to secondary ports out of p:choose?

Hi all,

I'm new to XProc and eager to use it to replace a rather complex shell-script driven sequence of XSLT calls. But I'm having trouble figuring out how to connect to the secondary port of a <p:choose> step.

There was a thread [1] on this list last March that I found helpful in getting the result port working, but the same technique that works for 'result' doesn't seem to apply to port 'secondary'.

As a toy example, I made myself a simple TEI document including a <div type="doc_a"> and a few short paragraphs. I made two XSLT stylesheets: process_a.xsl, which just adds @type='annotated' to every <p>, and process_b, which adds @type='burnished' to every <p>. In addition to the primary document output, both stylesheets also create a secondary <xsl:result-document> that is a simple XML structure that reports a count of the <p> elements. 

Without <p:choose>, I can get all the parts working as expected, but when the XSLT step is within a choice, I can't get the secondary port. Here's the toy XProc document that I'm using:

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
    xmlns:tei="http://www.tei-c.org/ns/1.0"
    xmlns:c="http://www.w3.org/ns/xproc-step" version="3.0">
    <p:input port="source"/>
    <p:output port="result" sequence="true"/>
    <p:variable name="doctype" select="(//tei:div/@type)[1]"/>
        
    <p:choose name="annotator">
        <p:when test="$doctype='doc_a'">
            <p:output port="result" primary="true"/>
            <p:output port="secondary" primary="false" sequence="true"/>
            <p:xslt>
                <p:with-input port="stylesheet" href="process_a.xsl"/>
            </p:xslt>
        </p:when> 
        <p:otherwise>
            <p:output port="result" primary="true"/>
            <p:output port="secondary" primary="false" sequence="true"/>Mor
            <p:xslt>
                <p:with-input port="stylesheet" href="process_b.xsl"/>
            </p:xslt>
        </p:otherwise>
    </p:choose>
    
    <p:for-each message="processing for-each">
        <p:with-input>
            <p:pipe port="secondary" step="annotator"/>
        </p:with-input>
        <p:identity message="* * *  storing data"></p:identity>
        <p:store href="data_notes.xml" message="* * * * * store data notes"/>
    </p:for-each>
        
    <p:store>
        <p:with-input>
            <p:pipe port="result" step="annotator"/>
        </p:with-input>
        <p:with-option name="href" select="concat('output_', $doctype, '.xml')"/>
    </p:store>
</p:declare-step> 

Both Morgana and Calabash produce the primary output as expected, without error, and show the "processing for-each" message, but no other messages (with the asterisks) within the for-each. On the XSLT side if I put a message inside the <xsl:result-document> element, that also shows up. But I can't figure out how to actually get the secondary document itself when the XSLT steps are inside <p:choose>.

Is there a way to do this? I could always push the branching logic into XSLT if necessary, but it would seem to make more sense at the XProc level.

Advice welcome. Thanks!

Doug Knox

[1] https://lists.w3.org/Archives/Public/xproc-dev/2024Mar/thread.html#msg0


Received on Monday, 20 January 2025 08:13:25 UTC