Re: Getting the current working directory

Hi Patrick,

The issue is a bit more complicated when it should also run on Windows, 
because pos:info only gives you the OS-specific path (starting with a 
drive letter and with backslashes as path separator), but in the XSLT 
you need a file: URI. We have an elaborate library for file URI 
normalization 
(https://github.com/transpect/xproc-util/blob/master/file-uri/xpl/file-uri.xpl), 
but it has too many dependencies to be quicky useful here (e.g., it 
depends on a catalog resolver), so I’m just hacking together some quick 
Windows path normalization here:

<p:declare-step
   xmlns:p="http://www.w3.org/ns/xproc"
   xmlns:pos="http://exproc.org/proposed/steps/os"
   xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">

   <p:output port="result" primary="true"/>

   <p:import href="http://xmlcalabash.com/extension/steps/library-1.0.xpl"/>

   <pos:info name="info"/>

   <p:add-attribute name="add-cwd-uri" attribute-name="cwd-uri" match="/*">
     <p:with-option name="attribute-value"
       select="if (matches(/*/@cwd, '^[a-z]:', 'i'))
               then concat('file:///', replace(/*/@cwd, '\\', '/'))
               else /*/@cwd"/>
   </p:add-attribute>

   <p:sink>
     <p:documentation>other stuff happens in the meantime…</p:documentation>
   </p:sink>

   <p:xslt name="Transformation">
     <p:with-param name="somefile" select="'somefile.xml'">
       <p:empty/>
     </p:with-param>
     <p:with-param name="cwd" select="/*/@cwd-uri">
       <p:pipe port="result" step="add-cwd-uri"/>
     </p:with-param>
     <p:input port="source">
       <p:inline>
         <bogo/>
       </p:inline>
     </p:input>
     <p:input port="stylesheet">
       <p:inline>
         <xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
           <xsl:param name="cwd"/>
           <xsl:param name="somefile"/>
           <xsl:template match="/">
             <out>
               <xsl:sequence select="string-join(($cwd, $somefile), '/')"/>
             </out>
           </xsl:template>
         </xsl:stylesheet>
       </p:inline>
     </p:input>
   </p:xslt>
</p:declare-step>




On 25.10.2017 14:44, Patrick Gundlach wrote:
> Hello David,
> 
> thank you for the answer, it looks promising. But I have to admit that I have now clue how to add this to my pipeline, which is something like
> 
> <p:declare-step
>    xmlns:p="http://www.w3.org/ns/xproc"
>    xmlns:pos="http://exproc.org/proposed/steps/os"
>    xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
>      <p:xslt name="Transformation">
>          <p:with-param name="somefile" select="'somefile.xml'">
>              <p:empty/>
>          </p:with-param>
>          <p:input port="source">
>              <p:document href="source.xml"/>
>          </p:input>
>          <p:input port="stylesheet">
>              <p:document href="transformation.xsl"/>
>          </p:input>
>      </p:xslt>
>      <p:store href="data.xml"/>
> </p:declare-step>
> 
> 
> Patrick
> 
> 
> 

-- 
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit.imsieke@le-tex.de, http://www.le-tex.de

Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930

Geschäftsführer: Gerrit Imsieke, Svea Jelonek,
Thomas Schmidt, Dr. Reinhard Vöckler

Received on Wednesday, 25 October 2017 13:07:53 UTC