[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT 2: File path to URI for non-XML file

Subject: Re: XSLT 2: File path to URI for non-XML file
From: Yves Forkl <Y.Forkl@xxxxxx>
Date: Wed, 08 Oct 2008 14:12:32 +0200
Re:  XSLT 2: File path to URI for non-XML file
Martin Honnen wrote:
Yves Forkl wrote: [...]
How can I "convert" the file path of the CSS file (i.e. $css_file) into a URI, given that the XSLT stylesheet is not located in the same directory? Functions targeting the URI of source document nodes won't help me much either, I fear.

The href attribute of xsl:result-document takes a URI reference (relative or absolute) so I am not sure where the problem is, is your variable value not simply a relative file URI?. If you want/need to resolve relative URIs then use http://www.w3.org/TR/xpath-functions/#func-resolve-uri

Sorry, I missed the fact that xsl:result-document needs a URI reference, so I need to convert my Windows file path already before.


Here is the function I came up with, which will convert an absolute Windows file path into a URI:

<xsl:function name="my:windowsfilepath_to_uri" as="xs:string">
  <xsl:param name="filepath" as="xs:string"/>
  <!-- Conversion steps:
       1) replace backslashes with slashes
       2) encode percent sign
       3) percent-encode URI fragment identifier character
       4) percent-encode characters illegal in URIs, using iri-to-uri
       5) add three slashes before drive letter
       6) prefix result with "file:" -->
  <xsl:value-of
    select="concat(
              'file:',
              replace(
                iri-to-uri(
                  replace(
                    replace(
                      replace($filepath, '\\', '/'),
                      '%',
                      '%25'),
                    '#',
                    '%23')),
                '^([A-Za-z]):',
                '///$1:'))"/>
</xsl:function>

This conforms to the rules stated in the IEBlog post "File URIs in Windows" [1]. Suggestions for improvements on the function are welcome.

Yves

[1] http://blogs.msdn.com/ie/archive/2006/12/06/file-uris-in-windows.aspx

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.