xsl-list
[Top] [All Lists]

Re: [xsl] function for getting filename

2006-09-01 05:00:11
"Andrew" == andrew welch 
<andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com> writes:

    >>
    andrew> tokenize(base-uri(.), '/')[last()]
    >>  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.

    Andrew> I think its safe to use on all nodes except namespace
    Andrew> nodes:

    Andrew> http://www.w3.org/TR/xpath-datamodel/#acc-summ-base-uri

    Andrew> Regarding xml:base you should get whatever's defined in
    Andrew> the xml:base shouldn't you?  In which case it's what the
    Andrew> XML author intended, and may be what you need to know at
    Andrew> that point, depending on your requirements.

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,
    >> then he can pass in the file name as a parameter. That is
    >> reliable.

    Andrew> Indeed, but in the general case you'll be fine with
    Andrew> tokenize(base-uri(.),'/')[last()]

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 realtion 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.
-- 
Colin Adams
Preston Lancashire

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--