Previous Up Next


cxf:head

cxf:head — Returns the first few lines of text file.

Synopsis

<p:declare-step type="cxf:head">
     <p:output port="result"/>
     <p:option name="href" required="true"/>                       <!-- anyURI -->
     <p:option name="count" required="true"/>                      <!-- int -->
     <p:option name="fail-on-error" select="'true'"/>              <!-- boolean -->
</p:declare-step>

Description

Returns the first count lines of the file named in href. If count is negative, the step returns all except those first lines.

The step returns a c:result element containing one c:line for each line. Lines are identified as described in [XML], 2.11 End-of-Line Handling.

If an error occurs, the step fails if fail-on-error is true; otherwise, the step returns a c:error element which may contain additional, implementation-defined information about the nature of the error.

Errors

Error Description
err:FU01 Occurs if the file named in href does not exist or cannot be read.
err:FU03 Occurs if the file named in href does not appear to be a text file. The exact conditions that constitute “does not appear to be” are implementation-defined.

Examples

Suppose that sonnet116.txt contains the following lines:

  1 Let me not to the marriage of true minds
    Admit impediments. Love is not love
    Which alters when it alteration finds,
    Or bends with the remover to remove:
  5 O no! it is an ever-fixed mark
    That looks on tempests and is never shaken;
    It is the star to every wandering bark,
    Whose worth's unknown, although his height be taken.
    Love's not Time's fool, though rosy lips and cheeks
 10 Within his bending sickle's compass come:
    Love alters not with his brief hours and weeks,
    But bears it out even to the edge of doom.
       If this be error and upon me proved,
       I never writ, nor no man ever loved.

The the following pipelines produce the results shown below them:

  1 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                    xmlns:cxf="http://xmlcalabash.com/ns/extensions/fileutils"
                    name="main" version="1.0">
      <p:output port="result"/>
  5 
      <p:import href="http://xmlcalabash.com/extension/steps/fileutils.xpl"/>
    
      <cxf:head count="3" href="sonnet116.txt"/>
    
 10 </p:declare-step>
  1 <c:result xmlns:c="http://www.w3.org/ns/xproc-step"><c:line>Let me not to the marriage of true minds</c:line>
    <c:line>Admit impediments. Love is not love</c:line>
    <c:line>Which alters when it alteration finds,</c:line>
    </c:result>
  1 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                    xmlns:cxf="http://xmlcalabash.com/ns/extensions/fileutils"
                    name="main" version="1.0">
      <p:output port="result"/>
  5 
      <p:import href="http://xmlcalabash.com/extension/steps/fileutils.xpl"/>
    
      <cxf:head count="5" href="sonnet116.txt"/>
    
 10 </p:declare-step>
  1 <c:result xmlns:c="http://www.w3.org/ns/xproc-step"><c:line>Let me not to the marriage of true minds</c:line>
    <c:line>Admit impediments. Love is not love</c:line>
    <c:line>Which alters when it alteration finds,</c:line>
    <c:line>Or bends with the remover to remove:</c:line>
  5 <c:line>O no! it is an ever-fixed mark</c:line>
    </c:result>
  1 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                    xmlns:cxf="http://xmlcalabash.com/ns/extensions/fileutils"
                    name="main" version="1.0">
      <p:output port="result"/>
  5 
      <p:import href="http://xmlcalabash.com/extension/steps/fileutils.xpl"/>
    
      <cxf:head count="0" href="sonnet116.txt"/>
    
 10 </p:declare-step>
<c:result xmlns:c="http://www.w3.org/ns/xproc-step"/>
  1 <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                    xmlns:cxf="http://xmlcalabash.com/ns/extensions/fileutils"
                    name="main" version="1.0">
      <p:output port="result"/>
  5 
      <p:import href="http://xmlcalabash.com/extension/steps/fileutils.xpl"/>
    
      <cxf:head count="-10" href="sonnet116.txt"/>
    
 10 </p:declare-step>
  1 <c:result xmlns:c="http://www.w3.org/ns/xproc-step"><c:line>Love alters not with his brief hours and weeks,</c:line>
    <c:line>But bears it out even to the edge of doom.</c:line>
    <c:line>   If this be error and upon me proved,</c:line>
    <c:line>   I never writ, nor no man ever loved.</c:line>
  5 </c:result>