XProc steps
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
p:directory-list
With the help of <p:directory-list>, the content of a directory within the file system can be read out. The desired directory is indicated by the “path“ option. If the processor does not find the directory when analysing the data, a dynamic error will be outputted. Furthermore, filtering rules can be defined. These have to contain a regular expression according to the XPath 2.0 rules. With the help of “include-filter“ it is possible to determine what shall be outputted. Analogous to this, you can define what shall not be displayed by using “exclude-filter“.
Example
In the following example the current directory (“.“) shall be read out.
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
<p:input port="source"> </p:input>
<p:output port="result"/>
<p:directory-list path="."/>
</p:declare-step>
The output is as follows:
<c:directory name="directory" xml:base="file:../Bachelorarbeit/SourceCodes/directory/">
<c:file name="directory.xpl"/>
<c:file name="file.xml"/>
<c:file name="file2.xml"/>
<c:file name="file3.txt"/>
<c:file name="file4.doc"/>
</c:directory>
Assuming the user only wants to have file outputs with the extension “*.txt“, the <p:directory> element requires a filter option as an attribute:
<p:directory-list include-filter=".*txt" path="."/>
As a result, the output would be as follows:
<c:directory name="directory" xml:base="file:../Bachelorarbeit/SourceCodes/directory/">
<c:file name="file3.txt"/>
</c:directory>
If the user wants to exclude all files having the extension “*.txt“, the filtering rule has to be adjusted:
<p:directory-list exclude-filter=".*txt" path="."/>
In any case, the result would be as follows:
<c:directory name="directory" xml:base="file:/Users/tg/Documents/FH%20Worms/6_Semester/Bachelorarbeit/SourceCodes/directory/">
<c:file name="example_14b_directory.xpl"/>
<c:file name="file.xml"/>
<c:file name="file2.xml"/>
<c:file name="file4.doc"/>
</c:directory>
If both variants are used, firstly the “include-filter“ and then the “exclude-filter“ rule applies.