[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: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 8 Oct 2008 13:45:43 +0100
RE:  XSLT 2: File path to URI for non-XML file
> 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.
> 

Unfortunately the mapping from Windows filenames to URIs implemented in the
MSDN blog that you reference is not necessarily the same as the mapping in
other bits of software. For example, Java maps UNC filenames (\\server\file)
to file:////server/file rather than file://server/file. Also, if you try to
create a file with %25 in the URI, I've no idea whether the resulting file
will contain "%" or "%25" - you'll have to try it and see. Basically, there
are no standards here, and your mileage depends on the environment you are
running in. I know for a fact that Saxon on .NET sometimes behaves
differently from Saxon on Java, though I can't point you to the specific
details.

Michael Kay
http://www.saxonica.com/

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.