0

Am parsing XML with file names with escaped characters. This is the file name on the server:
Account-V%29%27%22%3B%3A%3E.layout

When I apply the document function, it is automatically transforming the escaped characters.

`<xsl:apply-templates select="document('Account-V%29%27%22%3B%3A%3E.layout')/Layout"/>

The above yields an error as it cannot find this file on the server:
Account-V)'";:>.layout

Is there way to tell the document() function to not transform the escaped chars in the file? I tried wrapping this around variables but it did not work.

3 Answers3

1

If you're using XSLT 2.0, try using encode-for-uri()

select="document(encode-for-uri('Account-V%29%27%22%3B%3A%3E.layout'))/Layout"
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
0

The way that the URI you pass to the document() function gets dereferenced is in many ways implementation-defined, and many XSLT processors give you some control over it, for example by allowing you to supply a user-written URIResolver.

So I don't think the question can be answered without knowing your XSLT processor.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Hi Michael, this is Apache Xalan running on tomcat. OS developing on windows, will run on linux in production. Thanks for any assistance. – user2593166 Jul 18 '13 at 12:01
  • Found a workaround, which works. Isn't the prettiest, but before performing the XSLT, do a string in Java to replace such as `fileNames.replace("%","%25")` This forces the document() function to escape the percent sign to a percent, which generates the correct file name on the server. So %252E becomes %2E after the document function. Going to leave unanswered for a day or two to see if anybody has something better. – user2593166 Jul 18 '13 at 17:08
0

Found a workaround, which works. Isn't the prettiest, but before performing the XSLT, do a string in Java to replace such as fileNames.replace("%","%25") This forces the document() function to escape the percent sign to a percent, which generates the correct file name on the server.