Last active
October 15, 2017 19:20
-
-
Save dwcramer/9b892924f154f56db777187647776f47 to your computer and use it in GitHub Desktop.
XProc Preprocessing Parameters Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dcramer@Anatine ~ | |
$ /Applications/xmlcalabash-1.1.16-97/calabash -pgen.summary.tables='0' -pfoo='' Documents/git-repos/xproc-param-example/pipeline.xpl | |
INFO : Documents/git-repos/xproc-param-example/library.xpl:49:42: | |
Incoming Parameters: | |
<c:param-set xmlns:c="http://www.w3.org/ns/xproc-step"> | |
<c:param name="gen.summary.tables" namespace="" value="0"/> | |
<c:param name="foo" namespace="" value=""/> | |
</c:param-set> | |
Fixed-up Parameters: | |
<c:param-set xmlns:c="http://www.w3.org/ns/xproc-step"> | |
<c:param name="gen.summary.tables" namespace="" value="false"/> | |
</c:param-set> | |
INFO : Documents/git-repos/xproc-param-example/library.xpl:121:41: | |
gen.summary.tables=false | |
foo=default | |
<doc xmlns:l="http://thingbag.net/library" xmlns:c="http://www.w3.org/ns/xproc-step">Hello world!</doc> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" | |
xmlns:l="http://thingbag.net/library" | |
xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0" | |
name="main"> | |
<p:input port="source" primary="true"> | |
<p:inline> | |
<doc>Hello world!</doc> | |
</p:inline> | |
</p:input> | |
<p:output port="result"> | |
<p:pipe step="result" port="result"/> | |
</p:output> | |
<p:input port="params" kind="parameter" primary="true"/> | |
<p:import href="library.xpl"/> | |
<!-- Always include this to ward off evil --> | |
<p:import href="http://xmlcalabash.com/extension/steps/library-1.0.xpl"/> | |
<l:param-fixup name="param-fixup"/> | |
<p:sink/> | |
<l:my-main-pipeline> | |
<p:input port="source"> | |
<p:pipe port="source" step="main"/> | |
</p:input> | |
<p:input port="parameters"> | |
<p:pipe port="result" step="param-fixup"/> | |
</p:input> | |
<!-- The real work is nested in this step --> | |
</l:my-main-pipeline> | |
<p:identity name="result"/> | |
</p:declare-step> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<p:library | |
xmlns:p="http://www.w3.org/ns/xproc" | |
xmlns:c="http://www.w3.org/ns/xproc-step" | |
xmlns:l="http://thingbag.net/library" | |
version="1.0"> | |
<!-- Always include this to ward off evil --> | |
<p:import href="http://xmlcalabash.com/extension/steps/library-1.0.xpl"/> | |
<p:declare-step | |
xmlns:p="http://www.w3.org/ns/xproc" | |
xmlns:c="http://www.w3.org/ns/xproc-step" | |
version="1.0" | |
type="l:my-main-pipeline" | |
name="my-main-pipeline"> | |
<p:input port="source" primary="true"/> | |
<p:output port="result" primary="true"/> | |
<p:input port="parameters" kind="parameter"/> | |
<!-- all my steps go here --> | |
<l:test-params/> | |
<!-- all my steps go here --> | |
</p:declare-step> | |
<p:declare-step version="1.0" xmlns:p="http://www.w3.org/ns/xproc" | |
xmlns:db="http://docbook.org/ns/docbook" | |
xmlns:c="http://www.w3.org/ns/xproc-step" | |
xmlns:cx="http://xmlcalabash.com/ns/extensions" | |
type="l:param-fixup" | |
name="param-fixup"> | |
<p:input port="parameters" kind="parameter" primary="true"/> | |
<p:input port="source" primary="true"/> | |
<p:output port="result" primary="true"/> | |
<p:serialization port="result" omit-xml-declaration="false" indent="true"/> | |
<p:sink/> | |
<p:parameters name="consolidate-params"> | |
<p:input port="parameters"> | |
<p:pipe port="parameters" step="param-fixup"/> | |
</p:input> | |
</p:parameters> | |
<p:xslt name="fixup-params-xslt"> | |
<p:input port="source"> | |
<p:pipe step="consolidate-params" port="result"/> | |
</p:input> | |
<p:input port="parameters"> | |
<p:empty/> | |
</p:input> | |
<p:input port="stylesheet"> | |
<p:inline> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:c="http://www.w3.org/ns/xproc-step" | |
version="2.0"> | |
<xsl:variable name="sloppy-booleans" select="('gen.summary.tables','summary.tables.show.properties')"/> | |
<xsl:variable name="true-enough" select="('1','yes','true')"/> | |
<xsl:variable name="false-enough" select="('0','no','false')"/> | |
<xsl:template match="/"> | |
<xsl:message> | |
Incoming Parameters: | |
<xsl:copy-of select="/*"/> | |
Fixed-up Parameters: | |
<xsl:apply-templates/> | |
</xsl:message> | |
<xsl:apply-templates/> | |
</xsl:template> | |
<xsl:template match="node() | @*"> | |
<xsl:copy> | |
<xsl:apply-templates select="node() | @*"/> | |
</xsl:copy> | |
</xsl:template> | |
<!-- Remove empty params --> | |
<xsl:template match="c:param[@value = '']"/> | |
<xsl:template match="c:param[ $sloppy-booleans = @name ]"> | |
<xsl:variable name="value" select="if ($true-enough = @value) then 'true' else if ($false-enough = @value ) then 'false' else ''"/> | |
<xsl:if test="not($value = '')"> | |
<xsl:copy> | |
<xsl:apply-templates select="@name|@namespace"/> | |
<xsl:attribute name="value" select="$value"/> | |
</xsl:copy> | |
</xsl:if> | |
</xsl:template> | |
</xsl:stylesheet> | |
</p:inline> | |
</p:input> | |
</p:xslt> | |
</p:declare-step> | |
<p:declare-step type="l:test-params" | |
xmlns:p="http://www.w3.org/ns/xproc" | |
xmlns:c="http://www.w3.org/ns/xproc-step" | |
version="1.0" | |
name="test-params"> | |
<p:input port="source" primary="true"/> | |
<p:output port="result" primary="true"> | |
<p:pipe step="test-params-xslt" port="result"/> | |
</p:output> | |
<p:input port="parameters" kind="parameter"/> | |
<p:xslt name="test-params-xslt"> | |
<p:input port="source"> | |
<p:pipe step="test-params" port="source"/> | |
</p:input> | |
<p:input port="stylesheet"> | |
<p:inline> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:c="http://www.w3.org/ns/xproc-step" | |
version="2.0"> | |
<xsl:param name="gen.summary.tables" select="'default'"/> | |
<xsl:param name="foo" select="'default'"/> | |
<xsl:template match="node() | @*"> | |
<xsl:copy> | |
<xsl:apply-templates select="node() | @*"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="/"> | |
<xsl:apply-templates/> | |
<xsl:message> | |
gen.summary.tables=<xsl:value-of select="$gen.summary.tables"/> | |
foo=<xsl:value-of select="$foo"/> | |
</xsl:message> | |
</xsl:template> | |
</xsl:stylesheet> | |
</p:inline> | |
</p:input> | |
<p:input port="parameters"> | |
<p:pipe step="test-params" port="parameters"/> | |
</p:input> | |
</p:xslt> | |
</p:declare-step> | |
</p:library> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment