I needed today a way to create nice relative URI paths in XSLT. The point was, given a relative URI A
foo/bar/toto, and another relative URI B
baz/tutu supposed to be relative to the same base, calculate the URI path from A to B, in this case
Although it isn’t very complicated, I figured that other people may need this very same facility, since it’s a classical problem when using XSLT e.g. to build a Web site. Plus, I tried to make sure it would generate “nice” paths, for instance avoiding that the path generated to go from
../../foo/baz instead of the simpler
The code comes with an integrated Unit Test, handy for completing/adapting the code.