Reputation: 3351
I want to retrieve the name of the XML document i'm working on and I'm using the below Xpath.
<xsl:value-of select="fn:base-uri()"/>
and the resule that i get is having the entire path of the document i.e. like below
file:///C:/Users/home/Desktop/files/document/08192014/Raw.xml
so to get the only name of the XML document, in Altova the intelligence is showing some function substring-after-last()
, i used this like below.
<xsl:value-of select="substring-after-last(fn:base-uri(),'/')"/>
when i run this, i was getting some error as
Unknown function 'substring-after-last'
Warning location: xsl:stylesheet / xsl:template / html / body / section / div
/ xsl:value-of / @select
Details
XPST0017: The function call 'substring-after-last' does not match the
name of a function in the static context
please let me know how can i fix this problem and get the file name, also the same error is thrown for substring-before-last()
and some other functions given in Altova.
I use XSLT 2.0
when searching online I've found that there was a template created and a call was done to that template, i want to know why am I directly unable to use the given function Thanks
Upvotes: 0
Views: 6176
Reputation: 122374
The substring-after-last
function isn't part of the XPath standard, it's an Altova-specific extension function. To use it you need to declare the Altova extension namespace with xmlns:altova="http://www.altova.com/xslt-extensions"
and then refer to the function as altova:substring-after-last
.
If you want to stick to standard XPath functions for portability then you can rewrite it in terms of regular expressions and use the replace
function instead
replace(base-uri(), '^.*/', '')
The *
quantifier is greedy, so this will match the longest possible substring from the start of base-uri()
that ends with a slash, and replace it with an empty string (i.e. remove it altogether).
Upvotes: 9