Re: Faking primary ports?

Hi David,

On 08.09.2020 19:12, David Birnbaum wrote:
> Dear xproc-dev,
> 
> I'm still new to XProc 3.0 (and not very experienced with 1.0), and I've 
> written an XProc file that runs several XSLT transformations, each with 
> different input XML, XSLT, and output. It isn't really a pipeline 
> conceptually because each transformation is independent of the others, 
> so if my use of XProc (instead of, say, a shell script) reflects a  
> misunderstanding on my part of the types of operations for which XProc 
> is appropriate, I would be grateful for the correction. I am using 
> Morgana 0.9.4.2-beta.
> 
> If, though, XProc is a reasonable way to approach the task, I have two 
> semi-related questions:

There’s no reason not to use XProc for this task, although you could as 
well write a meta XSLT that invokes the individual transformations using 
fn:transform().

> 
> 1. My XProc begins by declaring primary ports that I don't use, because 
> each <p:xslt> step specifies its own XML input, its own stylesheet, its 
> own parameters (where relevant), and after each transformation I save 
> the result with <p:store>. At the end of the entire XProc I suppress the 
> default output with <p:sink/>. Declaring primary ports that I don't use 
> (because I handle the input and output for each of the transformations 
> separately) smells non-idiomatic, but omitting those declarations raises 
> error XS0032 (Primary input port 'source' on step '!1.1' is not bound). 
> Is there a more idiomatic strategy? My current primary port declarations 
> look like:
> 
> <p:input port="source" sequence="true">
>      <p:empty/>
> </p:input>
> <p:output port="result" sequence="true"/>

If you don’t need these ports, you can omit the declarations.

> 
> 2. One of my XSLT transformations does not read regular input; it gets 
> the XML that it transforms from two documents specified in variables 
> that it declares internally. If I were writing stand-alone XSLT 3 I 
> would declare an initial template in the stylesheet with 
> "xsl:initial-template" and use the "-it" switch (for Saxon) on the 
> command line. I can pass in dummy XML input, ignore it, and get the 
> output I want, but that, too, smells non-idiomatic. Is there an 
> idiomatic alternative? Of the half dozen mutually independent XSLT 
> transformations in my XProc, only one of them gets its data entirely 
> from variables; the others all use input supplied in the normal way, e.g.:

You can specify an initial template with <p:xslt template-name="…">. I’m 
not sure whether you can use the template designated as 
xsl:initial-template in XProc though. You’d need to supply an empty 
sequence or an empty string to the template-name option. Supplying an 
empty sequence is tantamount to not setting the option at all, so I 
don’t think that the processor can see a difference between supplying an 
empty sequence and no template-name option provided at all. On the other 
hand, if you explicitly supply an empty string using <p:with-option 
name="template-name" select="''"/>, it will try to cast this empty 
string to an xs:QName, which will fail. So I recommend that you use a 
named template with a name that is not xsl:initial-template.

Gerrit

> 
> <p:xslt>
>    <p:with-input port="stylesheet">
>      <p:document href="mappingsToHTML.xsl"/>
>    </p:with-input>
>    <p:with-input port="source">
>        <p:document href="mappings.xml"/>
>    </p:with-input>
> </p:xslt>
> <p:store href="mappings.html" name="mappingsHTML"/>
> 
> Best,
> 
> David
> 

-- 
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit.imsieke@le-tex.de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt

Received on Wednesday, 9 September 2020 06:01:47 UTC