-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e93e4de
commit baa516d
Showing
8 changed files
with
939 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<p:declare-step type="ccproc:directory-list" xmlns:p="http://www.w3.org/ns/xproc" version="1.0" | ||
xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:cx="http://xmlcalabash.com/ns/extensions" | ||
xmlns:cfn="http:/www.corbas.co.uk/ns/xslt/functions" | ||
xmlns:pkg="http://expath.org/ns/pkg" | ||
pkg:import-uri="http://www.corbas/co.uk/xproc-tools/directory-list" | ||
|
||
xmlns:ccproc="http://www.corbas.co.uk/ns/xproc/steps"> | ||
|
||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>This program and accompanying files are copyright 2008, 2009, 20011, 2012, 2013 Corbas | ||
Consulting Ltd.</p> | ||
<p>This program is free software: you can redistribute it and/or modify it under the terms | ||
of the GNU General Public License as published by the Free Software Foundation, either | ||
version 3 of the License, or (at your option) any later version.</p> | ||
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
PURPOSE. See the GNU General Public License for more details.</p> | ||
<p>You should have received a copy of the GNU General Public License along with this | ||
program. If not, see http://www.gnu.org/licenses/.</p> | ||
<p>If your organisation or company are a customer or client of Corbas Consulting Ltd you may | ||
be able to use and/or distribute this software under a different license. If you are not | ||
aware of any such agreement and wish to agree other license terms you must contact | ||
Corbas Consulting Ltd by email at <a href="mailto:corbas@corbas.co.uk" | ||
>corbas@corbas.co.uk</a>.</p> | ||
</p:documentation> | ||
|
||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>Generate directory listings. The include and exclude filters are only applied to file | ||
names and not to directories. The filters are implemented as regular expressions not | ||
glob patterns. This seems more useful than the standard approach. We've implemented this | ||
by handling the pattern matches in xslt rather than in the <code>p:directory-list</code> | ||
step. The patterns are not required to match the whole path name (unless desired)</p> | ||
</p:documentation> | ||
|
||
|
||
<p:output port="result"> | ||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>The result of the step is a <code>c:directory</code> element as defined for the | ||
<code>p:directory-list</code> step.</p> | ||
</p:documentation> | ||
<p:pipe port="result" step="filter-listing"/> | ||
</p:output> | ||
<p:option name="path" required="true"> | ||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>The path option defines the path to be searched.</p> | ||
</p:documentation> | ||
</p:option> | ||
<p:option name="include-filter" select="'___[[dummy]]___'"> | ||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>The <code>include-filter</code> option allows an option <em>regular expression</em> | ||
to be applied to either the file name or path name (depending on the value of | ||
<code>match-path</code> option). If the the match is successful, the file is | ||
retained unless excluded by the <code>exclude-filter</code> option.</p> | ||
<p>Directory names are not filtered and are always processed.</p> | ||
</p:documentation> | ||
</p:option> | ||
<p:option name="exclude-filter" select="'___[[dummy]]___'"> | ||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>The <code>exclude-filter</code> option allows an option <em>regular expression</em> | ||
to be applied to either the file name or path name (depending on the value of | ||
<code>match-path</code> option). If the the match is successful, the file is | ||
excluded from the results. The <code>exclude-filter</code> is applied after the | ||
<code>include-filter</code></p> | ||
<p>Directory names are not filtered and are always processed.</p> | ||
</p:documentation> | ||
</p:option> | ||
<p:option name="match-path" select="'false'"> | ||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>The <code>match-path</code> option determines whether or not the | ||
<code>include-filter</code> and <code>exclude-filter</code> options should apply | ||
to the whole path or just the file name. If set to <strong>true</strong> (case is | ||
insignificant) the file name will be combined with the path before the regular | ||
expressions are applied. If set to any other value then only the file name is | ||
tested.</p> | ||
</p:documentation> | ||
</p:option> | ||
|
||
|
||
|
||
<!-- get the listing fo the top directory --> | ||
<p:directory-list name="listing"> | ||
<p:with-option name="path" select="$path"/> | ||
</p:directory-list> | ||
|
||
<!-- filter --> | ||
<p:xslt name="filter-listing"> | ||
<p:input port="source"> | ||
<p:pipe port="result" step="listing"/> | ||
</p:input> | ||
<p:input port="stylesheet"> | ||
<p:inline> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" | ||
xmlns:c="http://www.w3.org/ns/xproc-step" | ||
xmlns:cfn="http:/www.corbas.co.uk/ns/xslt/functions" | ||
exclude-result-prefixes="xs xd" version="2.0"> | ||
<xd:doc scope="stylesheet"> | ||
<xd:desc> | ||
<xd:p><xd:b>Created on:</xd:b> Jun 4, 2014</xd:p> | ||
<xd:p><xd:b>Author:</xd:b> nicg</xd:p> | ||
<xd:p/> | ||
</xd:desc> | ||
</xd:doc> | ||
|
||
<xsl:param name="include-filter" as="xs:string"/> | ||
<xsl:param name="exclude-filter" as="xs:string"/> | ||
<xsl:param name="match-path" as="xs:string"/> | ||
|
||
<xsl:template match="c:directory|c:other|c:file[cfn:include-file(.)]|@*|text()"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="@*|node()"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
|
||
<xsl:template match="c:file"/> | ||
|
||
<xsl:function name="cfn:include-file" as="xs:boolean"> | ||
<xsl:param name="node" as="element(c:file)"/> | ||
|
||
<!-- search whole path if match-path is set to true, else file name --> | ||
<xsl:variable name="search-string" | ||
select="if (lower-case($match-path) = 'true') | ||
then concat($node/../@xml:base, $node/@name) else $node/@name"/> | ||
|
||
<!-- potential include if no filter or matches filter --> | ||
<xsl:variable name="potential-include" | ||
select="if ($include-filter = '') then true() | ||
else matches($search-string, $include-filter)"/> | ||
|
||
<!-- potential exclude if there is a filter and it matches --> | ||
<xsl:variable name="potential-exclude" | ||
select="if ($exclude-filter = '') then false() | ||
else matches($search-string, $exclude-filter)"/> | ||
|
||
<!-- include if potential-include and not potential-exclude --> | ||
<xsl:value-of select="$potential-include and not($potential-exclude)"/> | ||
|
||
</xsl:function> | ||
|
||
</xsl:stylesheet> | ||
</p:inline> | ||
</p:input> | ||
<p:with-param name="include-filter" | ||
select="if ($include-filter = '___[[dummy]]___') then '' else $include-filter"/> | ||
<p:with-param name="exclude-filter" | ||
select="if ($exclude-filter = '___[[dummy]]___') then '' else $exclude-filter"/> | ||
<p:with-param name="match-path" select="$match-path"/> | ||
</p:xslt> | ||
|
||
|
||
|
||
</p:declare-step> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<p:library xmlns:p="http://www.w3.org/ns/xproc" | ||
xmlns:data="http://www.corbas.co.uk/ns/transforms/data" | ||
xmlns:ccproc="http://www.corbas.co.uk/ns/xproc/steps" | ||
xmlns:cx="http://xmlcalabash.com/ns/extensions" xmlns:c="http://www.w3.org/ns/xproc-step" | ||
xmlns:pkg="http://expath.org/ns/pkg" | ||
pkg:import-uri="http://www.corbas/co.uk/xproc-tools/load-sequence-from-file" version="1.0"> | ||
|
||
<p:declare-step type="ccproc:load-sequence-from-file" name="load-sequence-from-file"> | ||
|
||
<p:documentation xmlns="http://wwww.w3.org/1999/xhtml"> | ||
<p>This program and accompanying files are copyright 2008, 2009, 20011, 2012, 2013 | ||
Corbas Consulting Ltd.</p> | ||
<p>This program is free software: you can redistribute it and/or modify it under the | ||
terms of the GNU General Public License as published by the Free Software | ||
Foundation, either version 3 of the License, or (at your option) any later | ||
version.</p> | ||
<p>This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
PARTICULAR PURPOSE. See the GNU General Public License for more details.</p> | ||
<p>You should have received a copy of the GNU General Public License along with this | ||
program. If not, see http://www.gnu.org/licenses/.</p> | ||
<p>If your organisation or company are a customer or client of Corbas Consulting Ltd you | ||
may be able to use and/or distribute this software under a different license. If you | ||
are not aware of any such agreement and wish to agree other license terms you must | ||
contact Corbas Consulting Ltd by email at <a href="mailto:corbas@corbas.co.uk" | ||
>corbas@corbas.co.uk</a>.</p> | ||
</p:documentation> | ||
|
||
<p:documentation xmlns="http://wwww.w3.org/1999/xhtml"> | ||
<revhistory xmlns="http://docbook.org/ns/docbook"> | ||
<revision> | ||
<revnumber>1</revnumber> | ||
<date>2013-01-14</date> | ||
<revremark>Initial Version</revremark> | ||
<authorinitials>NG</authorinitials> | ||
</revision> | ||
<revision> | ||
<revnumber>2</revnumber> | ||
<date>2014-01-06</date> | ||
<revremark>Added support for import statements in manifest files.</revremark> | ||
<authorinitials>NG</authorinitials> | ||
</revision> | ||
</revhistory> | ||
<p>Script to read an xml manifest file containing a list of files, load them and | ||
return a sequence of the files in the order they were contained in the input file. | ||
The input file should validate against <span class="filename">manifest.rng</span>. The <code | ||
class="attribute">href</code> attribute of each <code class="element">item</code> | ||
element is used to identify the files to be loaded. The file names are resolved | ||
agains the base uri of the manifest file (or their own base if overridden via <code | ||
class="attribute">xml:base</code>. </p> | ||
</p:documentation> | ||
|
||
|
||
<p:input port="source" primary="true"> | ||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>The source port should provide a | ||
manifest document as described above.</p> | ||
</p:documentation> | ||
</p:input> | ||
|
||
<p:output port="result" primary="true" sequence="true"> | ||
<p:documentation xmlns="http://www.w3.org/1999/xhtml"> | ||
<p>The result port will contain a sequence | ||
of documents loaded from the list contained on the input port</p> | ||
</p:documentation> | ||
<p:pipe port="result" step="load-iterator"/> | ||
</p:output> | ||
|
||
<p:import href="http://xmlcalabash.com/extension/steps/library-1.0.xpl"/> | ||
|
||
<!-- Load up manifest, processing imports as we go in order to get | ||
a flat manifest for the next stage --> | ||
<p:xslt version="2.0" name="process-imports"> | ||
|
||
<p:input port="source"> | ||
<p:pipe port="source" step="load-sequence-from-file"/> | ||
</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" version="2.0"> | ||
|
||
|
||
<xsl:template match="@*|node()"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="@*|node()"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
|
||
<xsl:template match="data:import"> | ||
<xsl:variable name="imported" select="doc(@href)/*/*"/> | ||
<xsl:apply-templates select="$imported"/> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> | ||
</p:inline> | ||
</p:input> | ||
|
||
</p:xslt> | ||
|
||
<!-- Loop over input and load each file in turn. | ||
We don't handle errors here because the default behaviour (exit with error) | ||
is the desired behaviour and the error message is just fine --> | ||
<p:for-each name="load-iterator"> | ||
|
||
<p:output port="result" primary="true"/> | ||
|
||
<p:iteration-source select="/data:manifest/*"> | ||
<p:pipe port="result" step="process-imports"/> | ||
</p:iteration-source> | ||
|
||
<p:choose> | ||
|
||
<p:when test="/data:item"> | ||
|
||
<p:variable name="href" | ||
select="p:resolve-uri(/data:item/@href, p:base-uri(/data:item))"/> | ||
|
||
<!-- <cx:message> | ||
<p:with-option name="message" select="concat('item: ', $href)"/> | ||
</cx:message> --> | ||
|
||
<p:load name="load-doc"> | ||
<p:with-option name="href" select="$href"/> | ||
</p:load> | ||
|
||
</p:when> | ||
|
||
<p:otherwise> | ||
|
||
<p:variable name="stylesheet" | ||
select="p:resolve-uri(/data:processed-item/@stylesheet, | ||
p:base-uri(/data:processed-item))"/> | ||
<p:variable name="href" | ||
select="p:resolve-uri(/data:processed-item/data:item/@href, | ||
p:base-uri(/data:processed-item/data:item))"/> | ||
|
||
<!--<cx:message> | ||
<p:with-option name="message" select="concat('stylesheet: ', $stylesheet)"/> | ||
</cx:message>--> | ||
|
||
<p:load name="load-stylesheet"> | ||
<p:with-option name="href" select="$stylesheet"/> | ||
</p:load> | ||
|
||
<!--<cx:message> | ||
<p:with-option name="message" select="concat('item: ', $href)"/> | ||
</cx:message>--> | ||
|
||
<p:load name="load-data"> | ||
<p:with-option name="href" select="$href"/> | ||
</p:load> | ||
|
||
|
||
<p:xslt> | ||
<p:input port="parameters"> | ||
<p:empty/> | ||
</p:input> | ||
<p:input port="stylesheet"> | ||
<p:pipe port="result" step="load-stylesheet"/> | ||
</p:input> | ||
<p:input port="source"> | ||
<p:pipe port="result" step="load-data"/> | ||
</p:input> | ||
</p:xslt> | ||
|
||
</p:otherwise> | ||
</p:choose> | ||
|
||
<p:identity/> | ||
|
||
</p:for-each> | ||
|
||
</p:declare-step> | ||
|
||
</p:library> |
Oops, something went wrong.