XPath URL with fn prefix not working

The following XLST code works fine: -

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <xsl:for-each select="bookstore/book"> <xsl:if test="starts-with(author, 'W')"> <!-- Line 1 --> <xsl:value-of select="title" /> &#160; by <xsl:value-of select="author" /> <br/> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> 

Here, I directly use the XPath String function starts with () in line 1.

Now, according to W3Schools , adding a namespace for XPath functions ( http://www.w3.org/2005/xpath-functions ), the following code does not work: -

 <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="1.0"> <xsl:template match="/"> <xsl:for-each select="bookstore/book"> <xsl:if test="fn:starts-with(author, 'W')"> <!-- Line 2 --> <xsl:value-of select="title" /> &#160; by <xsl:value-of select="author" /> <br/> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> 

Here I use the XPath function with my prefix attached to the namespace.

IE shows that "Error: namespace" http://www.w3.org/2005/xpath-functions ' does not contain any functions "I checked the URL and it has functions.

Where am I mistaken? And if I can use all XPath functions with the transform URL itself, then why is there a separate URL for XPath functions?

+4
source share
2 answers

Now, according to W3Schools, adding a namespace for XPath functions (http://www.w3.org/2005/xpath-functions), the following code does not work: -

...

Here I am using the XPath function with my prefix attached to the namespace.

IE shows that "Error: namespace" "http://www.w3.org/2005/xpath-functions" does not contain any functions "

Try to avoid "w3schools". See why at: http://w3fools.com/ .

The F and O namespace that you tried to use was created many years after the publication of the W3C XPath 1.0 and XSLT 1.0 recommendations. It applies only to XPath 2.0 features, and this namespace is unknown to XPath 1.0 / XSLT 1.0 processors.

Even with XPath 2.0 / XSLT 2.0, there is no need to use a namespace . In this namespace, name names without prefix are counted.

Solution :

Just no prefix of any standard XPath functions.

+1
source

This is because IE uses MSXML, which only supports XPath 1.0. In XPath / XSLT 1.0, there is no need to prefix the standard XPath functions.

+2
source

Source: https://habr.com/ru/post/1402371/


All Articles