Closed martinklepsch closed 5 years ago
But maybe this is also perfectly acceptable:
(xslt/transform (xslt/compile-source (StreamSource. (io/input-stream to-html-xslt))) (slurp f))
I don't think you're missing anything. Your latter example is probably the most straightforward solution at the moment.
Unfortunately, it seems I've made a poor API choice here: similarly to compile-edn
, compile-xslt
should probably be a function that accepts anything that can be turned into a java.io.InputStream
. As in:
(xslt/transform (xslt/compile-xslt (io/file "resources/foo.xsl")))
;; or
(xslt/transform (xslt/compile-xslt (io/resource "foo.xslt")))
However, I don't want to break backwards compatibility.
One option would be to modify compile-xslt
such that it checks whether the input argument is already something that can be turned into an InputStream
. If yes, simply pass it to io/input-stream
. Otherwise, assume it is a file path and compile it as before.
Maybe checking whether the input arguments ~satisfies~ is an instance of IOFactory
would do the trick? Didn't have the time to investigate more than that yet, though.
PR more than welcome if you're up to it!
Actually, it appears that io/input-stream
already considers a string argument it can't parse into a URL a file path, so the fix is fortunately quite simple.
Pushed v0.2.2. With it, this should work:
(xslt/compile-xslt (io/resource "path/to/classpath/stylesheet.xsl"))
That's a sweet solution! 👍
Hello again,
I'm wondering if there's any particular support to compile XSLT stylesheets from the classpath or a raw string?
This works well when the file is a regular file in the filesystem but fails if the file is within a Jar.
It seems that it would be possible to turn a resource into an input stream and then into a
StreamSource
.Am I missing something or is this just something you didn't yet need? Would be happy to provide a PR.