Jump to content

xpath functions


andreathedove

Recommended Posts

Perhaps EXSLT's regexp:replace function... but wait. You were using MSXML (ASP), correct? Well, then... I'm sorry to disappoint you, but that EXSLT function is not available in it. I think the MSXSL implementation on the site would integrate it I believe. As long as you include it in your stylesheet.Unless you have an XSLT 2.0 processor, you're stuck with the above.

Link to comment
Share on other sites

Perhaps EXSLT's regexp:replace function... but wait. You were using MSXML (ASP), correct? Well, then... I'm sorry to disappoint you, but that EXSLT function is not available in it. I think the MSXSL implementation on the site would integrate it I believe. As long as you include it in your stylesheet.Unless you have an XSLT 2.0 processor, you're stuck with the above.
... yes I use ASP.Andrea
Link to comment
Share on other sites

<xsl:value-of select="translate('Andrea_The_Dove','_',' ')"/>This will do what your example was asking for. If you have more elaborate replacing needs, you may be able to use translate, or perhaps a javascript extension to the XSLT. You could then invoke the replace method of the string object.

Link to comment
Share on other sites

<xsl:value-of select="translate('Andrea_The_Dove','_',' ')"/>This will do what your example was asking for. If you have more elaborate replacing needs, you may be able to use translate, or perhaps a javascript extension to the XSLT. You could then invoke the replace method of the string object.
thanks very much
Link to comment
Share on other sites

...<a href="game.asp?gameid={title}"><b><xsl:value-of select="title"/></b></a> <br /><xsl:value-of select="andy:shortdescription"/></xsl:for-each>..."andy:shortdescription"this give me the unspecifed namespace declaration erro, why ?ThanksAndrea
Well, have you declared this namespace? Even if you have, have you put the prefix in the extension-elements-prefix attribute?
Link to comment
Share on other sites

Read slowly, and a few times over...XML namespaces are identifiers. You know... the prefix "xsl:" in elements is actually associated with a URI, declared at the top of the document (http://www.w3.org/1999/XSL/Transform). That URI identifies XSLT as a language used in the document. It's NOT a location the processor follows. It's only used to identify XSLT. The same thing goes for any extension XSLT functions. They need namespace prefix with an associated URI to identify them as extension functions. Without them, the XSLT processor thinks they are standard XSLT functions, which they are not. Extension functions can take different URIs to identify themselves, meaning you can have a few prefixes you'll use in a single document.So the question to you is practically "is the prefix 'andy:' associated with any URI to identify 'shortdescription' as an external function?". In order to declare such a prefix, you'd go to the top of your XSLT stylesheet that has this function, and it will look:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:andy="some-URI-used-to-identify-this-function">

However, scince this function is an XSLT extension, XSLT needs to be told that this prefix is an extension to it. To do that, you add this prefix in a special list in the extension-element-prefixes attribute. Like so:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:andy="some-URI-used-to-identify-this-function" extension-element-prefixes="andy">

Now, XSLT knows "andy" is part of the some-URI-used-to-identify-this-function namespace, and that this namespace is an extension to XSLT. if you need to add more extenions, extension-element-prefixes' value would look like "andy anotherPrefix thirdPrefix andSoOn" where the prefixes after andy must of course be declared too.

Link to comment
Share on other sites

Ah, thank you very much boen_robot, I was also not really clear about these namespaces and declaration stuff. Your explanation helped me to understand more about it. :)(edit)I edited my XSLT with the following line:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions">

Theoratically, it will allow me to use the prefix "fn:" for all the xPath functions (as instructed on XPath, XQuery, and XSLT Functions tutorial page), but nevertheless IE return the error "Namespace 'http://www.w3.org/2005/02/xpath-functions' does not contain any functions".Is this because of MSXML limitation? I assumed that IE 7 in a normal Windows XP uses MSXML parser.

Link to comment
Share on other sites

@andreathedove, "some-URI-used-to-identify-this-function" is only an example. It's not the actual URI you need and I can't know what the URI you need is. Check up with whoever suggested you to use that function (speaking of which, what does it do anyway?).@Quastarâ„¢ the XPath reference on W3Schools is TERRIBLY WRONG. Not only the functions are outdated (the reference was written when XPath 2.0 was early candidate reccomendation), but this namespace does NOT unlock XPath 2.0 under XSLT 1.0. Not only that, but XPath 2.0 will NOT be available for XSLT 1.0 AT ALL. In order to use XPath 2.0 functions, you'll need an XSLT 2.0 processor, or another XPath 2.0 aware environment (such as XQuery, or future DOM implementations).

Link to comment
Share on other sites

@andreathedove, "some-URI-used-to-identify-this-function" is only an example. It's not the actual URI you need and I can't know what the URI you need is. Check up with whoever suggested you to use that function (speaking of which, what does it do anyway?).@Quastarâ„¢ the XPath reference on W3Schools is TERRIBLY WRONG. Not only the functions are outdated (the reference was written when XPath 2.0 was early candidate reccomendation), but this namespace does NOT unlock XPath 2.0 under XSLT 1.0. Not only that, but XPath 2.0 will NOT be available for XSLT 1.0 AT ALL. In order to use XPath 2.0 functions, you'll need an XSLT 2.0 processor, or another XPath 2.0 aware environment (such as XQuery, or future DOM implementations).
there is not a standard URI ?
Link to comment
Share on other sites

there is not a standard URI ?
For XPath 2.0? No, there isn't. Those functions will be part of the core library (no namespace required- as with XPath 1.0 under XSLT 1.0).If you mean for your andy:shortdescription function... well... I don't know. Ask the creator.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...