1. | How to get style-sheet relative paths? |
XSLT 2.0 would allow you to write href="{resolve-uri('ReportStyle.css')}" But of course that doesn't help very much because you need a solution that works in IE. Unfortunately I don't think it's possible: although the base URI of a stylesheet instruction is part of the context in 1.0, it's accessible only through the document() function. | |
2. | How to determine absolute path of processed xml |
In XSLT 2.0 you can do document-uri(/). It only work if the systemId is actually known, which may not be the case if for example the source was supplied as a DOMSource. A more portable solution is to pass the URI to the stylesheet as a parameter. | |
3. | Get the current xml file name |
document (concat(document-uri(/),'/../','nextfile.xml')) should do the trick. If you are using XSLT 2.0, you can use the resolve-uri function which will be a bit neater. Owen Rees adds If you can use document-uri then you should be able to use resolve-uri - both are new in XPath 2.0. document(resolve-uri('nextfile.xml',document-uri(/))) See also base-uri. | |
4. | Obtain source file name |
In xslt 2.0 I use: tokenize(base-uri(.), '/')[last()] Colin Adams adds That's not sound - . might not be the document node - if it's an element with an xml:base attribute in scope, then you may get something very spurious indeed. Using document-uri in your expression looks sounder. Andrew responds with I think its safe to use on all nodes except namespace nodes: W3C Regarding xml:base you should get whatever's defined in the xml:base shouldn't you? In which case it's what the XML author intended, and may be what you need to know at that point, depending on your requirements. And Colin comes back (Ednote: I like these threads :-) The OP's requirements were the filename, not the base-uri. if his requirements were indeed the XML author's view of the base-uri, then it would be perfect. >> If the OP is invoking a transformation from the command line, Well, no. (and not even with document-uri substituted for base-uri). What you get is the last path segment, plus possible query parameters and fragment identifier, from the base, or document, uri. In general, this has no relation to a file name. In the case of a file: uri, even then it is not sound. If you want the file name, and you get instead a fragment identifier tacked on a file name, you don't get what you want. So a further tokenization is necessary to remove query parameters and fragment identifier. If it's not a file uri, then all bets are off. David Carlisle comes in with I'd probably do replace(base-uri(/),'.*/','') to remove the path component rather than tokenize and last() but it probably doesn't make much difference really. You could add |[\?#].* to the regex to also remove query and fragment identifiers if they were a possibility. |