Skip to content

Instantly share code, notes, and snippets.

@gimsieke
Created October 15, 2017 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gimsieke/f3b5534658b2f7240d579230ca17fc4a to your computer and use it in GitHub Desktop.
Save gimsieke/f3b5534658b2f7240d579230ca17fc4a to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://www.w3.org/ns/xproc-step"
version="1.0"
name="test-params">
<p:input port="params" kind="parameter" primary="true"/>
<p:input port="source" primary="true">
<p:inline>
<doc>Hello world!</doc>
</p:inline>
</p:input>
<p:output port="result" primary="true"/>
<p:serialization port="result" omit-xml-declaration="false" indent="true"/>
<p:sink>
<p:documentation>Discard source for the time being…</p:documentation>
</p:sink>
<p:parameters name="consolidate-params">
<p:input port="parameters">
<p:pipe port="params" step="test-params"/>
</p:input>
</p:parameters>
<p:xslt name="manipulate-params">
<p:input port="source">
<p:pipe port="result" step="consolidate-params"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
<p:input port="stylesheet">
<p:inline>
<xsl:stylesheet version="2.0">
<xsl:template match="* | @*">
<xsl:copy>
<xsl:apply-templates select="@*, node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="c:param[@name = 'foo']/@value">
<xsl:attribute name="{name()}" select="'baz'"/>
</xsl:template>
<xsl:template match="c:param[starts-with(@name, 'other')]">
<xsl:copy>
<xsl:attribute name="name" select="replace(@name, '^other-?', '')"/>
<xsl:attribute name="value" select="replace(@name, '^other-?', '')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</p:inline>
</p:input>
</p:xslt>
<p:store href="manipulated-params.xml" indent="true" omit-xml-declaration="false"/>
<!-- no p:sink if p:store precedes this (p:store doesn’t have a primary output) -->
<!-- <p:sink/>-->
<p:group name="group">
<p:xslt name="transform-source">
<p:input port="source">
<p:pipe port="source" step="test-params"/>
</p:input>
<p:input port="parameters">
<p:pipe port="result" step="manipulate-params"/>
</p:input>
<p:input port="stylesheet">
<p:inline>
<xsl:stylesheet version="2.0">
<xsl:param name="param" as="xs:string?"/>
<xsl:param name="other-param" as="xs:string?"/>
<xsl:param name="foo" as="xs:string?"/>
<xsl:template match="/">
<out>
<param name="foo" value="{$foo}"/>
<param name="other-param" value="{$other-param}"/>
<param name="param" value="{$param}"/>
</out>
</xsl:template>
</xsl:stylesheet>
</p:inline>
</p:input>
</p:xslt>
</p:group>
</p:declare-step>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment