Skip to content

Instantly share code, notes, and snippets.

@xquery
Created February 13, 2015 16:54
Show Gist options
  • Save xquery/350831de91841b84edd9 to your computer and use it in GitHub Desktop.
Save xquery/350831de91841b84edd9 to your computer and use it in GitHub Desktop.
xslt fold example - apply a series of xslt against a single source doc
the following is an example of a left fold xslt
java -jar /Applications/depify-1.0/deps/xmlcalabash/calabash.jar -isource=test.xml -istylesheets=test1.xsl -istylesheets=test2.xsl -oresult=- xslt-fold.xpl
<p:declare-step version="1.0"
xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step"
xmlns:ex="http://www.example.com"
name="main">
<p:input port="source"/>
<p:output port="result"/>
<p:input port="stylesheets" sequence="true"/>
<p:declare-step name="xslt-fold" type="ex:xslt-fold">
<p:input port="source"/>
<p:output port="result"/>
<p:input port="stylesheets" sequence="true"/>
<p:split-sequence name="current-xslt" test="position() eq 1">
<p:input port="source">
<p:pipe step="xslt-fold" port="stylesheets"/>
</p:input>
</p:split-sequence>
<p:count name="count">
<p:input port="source">
<p:pipe step="current-xslt" port="not-matched"/>
</p:input>
</p:count>
<p:xslt name="xslt">
<p:input port="source">
<p:pipe step="xslt-fold" port="source"/>
</p:input>
<p:input port="stylesheet">
<p:pipe step="current-xslt" port="matched"/>
</p:input>
<p:input port="parameters">
<p:empty/>
</p:input>
</p:xslt>
<p:choose>
<p:xpath-context>
<p:pipe step="count" port="result"/>
</p:xpath-context>
<p:when test="xs:integer(.) eq 0">
<p:identity>
<p:input port="source">
<p:pipe step="xslt" port="result"/>
</p:input>
</p:identity>
</p:when>
<p:otherwise>
<ex:xslt-fold>
<p:input port="source">
<p:pipe step="xslt" port="result"/>
</p:input>
<p:input port="stylesheets">
<p:pipe step="current-xslt" port="not-matched"/>
</p:input>
</ex:xslt-fold>
</p:otherwise>
</p:choose>
</p:declare-step>
<ex:xslt-fold>
<p:input port="source">
<p:pipe step="main" port="source"/>
</p:input>
<p:input port="stylesheets">
<p:pipe step="main" port="stylesheets"/>
</p:input>
</ex:xslt-fold>
</p:declare-step>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment