Previous Up Next

ex:recursive-directory-list

ex:recursive-directory-list — Performs p:directory-list recursively.

Synopsis

<p:declare-step type="exrecursive-directory-list">
     <p:output port="result"/>
     <p:option name="path" required="true"/>                       <!-- anyURI -->
     <p:option name="include-filter"/>                             <!-- RegularExpression -->
     <p:option name="exclude-filter"/>                             <!-- RegularExpression -->
     <p:option name="depth" select="-1"/>                          <!-- integer -->
</p:declare-step>

Description

The ex:recursive-directory-list step lists the contents of the specified directory on the filesystem. Unlike the standard p:directory-list step, ex:recursive-directory-list expands all subdirectories recursively.

The path, include-filter, and exclude-filter options are the same as the p:directory-list options of the same name.

The depth option limits the recursive depth of the process. A value of “-1” specifies an unbounded depth.

Errors

Error Description
err:C0012 Occurs if the step cannot read the specified directory due to access restrictions or if the environment doesn't support the notion of a hierarchical directory structure.
err:C0017 Occurs if the absolute path does not specify a directory.

Examples

TBD
TBD

Implementation

The ex:recursive-directory-list step can be implemented directly in XProc:

  1 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
    		xmlns:c="http://www.w3.org/ns/xproc-step"
    		xmlns:cx="http://xmlcalabash.com/ns/extensions"
                    type="cx:recursive-directory-list"
  5                 version="1.0">
      <p:output port="result"/>
      <p:option name="path" required="true"/>
      <p:option name="include-filter"/>
      <p:option name="exclude-filter"/>
 10   <p:option name="depth" select="-1"/>
    
      <p:choose>
        <p:when test="p:value-available('include-filter')
                      and p:value-available('exclude-filter')">
 15       <p:directory-list>
            <p:with-option name="path" select="$path"/>
            <p:with-option name="include-filter" select="$include-filter"/>
            <p:with-option name="exclude-filter" select="$exclude-filter"/>
          </p:directory-list>
 20     </p:when>
    
        <p:when test="p:value-available('include-filter')">
          <p:directory-list>
            <p:with-option name="path" select="$path"/>
 25         <p:with-option name="include-filter" select="$include-filter"/>
          </p:directory-list>
        </p:when>
    
        <p:when test="p:value-available('exclude-filter')">
 30       <p:directory-list>
            <p:with-option name="path" select="$path"/>
            <p:with-option name="exclude-filter" select="$exclude-filter"/>
          </p:directory-list>
        </p:when>
 35 
        <p:otherwise>
          <p:directory-list>
            <p:with-option name="path" select="$path"/>
          </p:directory-list>
 40     </p:otherwise>
      </p:choose>
    
      <p:viewport match="/c:directory/c:directory">
        <p:variable name="name" select="/*/@name"/>
 45 
        <p:choose>
          <p:when test="$depth != 0">
            <p:choose>
              <p:when test="p:value-available('include-filter')
 50                         and p:value-available('exclude-filter')">
                <cx:recursive-directory-list>
                  <p:with-option name="path" select="concat($path,'/',$name)"/>
                  <p:with-option name="include-filter" select="$include-filter"/>
                  <p:with-option name="exclude-filter" select="$exclude-filter"/>
 55               <p:with-option name="depth" select="$depth - 1"/>
                </cx:recursive-directory-list>
              </p:when>
    
              <p:when test="p:value-available('include-filter')">
 60             <cx:recursive-directory-list>
                  <p:with-option name="path" select="concat($path,'/',$name)"/>
                  <p:with-option name="include-filter" select="$include-filter"/>
                  <p:with-option name="depth" select="$depth - 1"/>
                </cx:recursive-directory-list>
 65           </p:when>
    
              <p:when test="p:value-available('exclude-filter')">
                <cx:recursive-directory-list>
                  <p:with-option name="path" select="concat($path,'/',$name)"/>
 70               <p:with-option name="exclude-filter" select="$exclude-filter"/>
                  <p:with-option name="depth" select="$depth - 1"/>
                </cx:recursive-directory-list>
              </p:when>
    
 75           <p:otherwise>
                <cx:recursive-directory-list>
                  <p:with-option name="path" select="concat($path,'/',$name)"/>
                  <p:with-option name="depth" select="$depth - 1"/>
                </cx:recursive-directory-list>
 80           </p:otherwise>
            </p:choose>
          </p:when>
          <p:otherwise>
    	<p:identity/>
 85       </p:otherwise>
        </p:choose>
      </p:viewport>
    
    </p:declare-step>