English 中文(简体)
XSLT 1.0 How to extend with fn (function namespace)
原标题:

I was wondering how I can possible extend XSLT 1.0 so that I can use functions from fn function namespace at http://www.w3schools.com/Xpath/xpath_functions.asp

I was just told that the system is using MSXML XSLT processor from now on. All my stylesheets were written in 2.0 ... So now I m stack, nothing is working and don t know how I can use functions for example from fn namespace.

I was wondering whether it will be possible to extend XSLT 1.0 somehow, because I use lots of those functions. Or what do I do now? I m absolutely lost and frustrated.

Would really appreciate any help!

Thanks a lot!

最佳回答

If you are stuck with MSXML as your processor, I think your only is to go with option 2 in Obalix s answer, but you will probably have to write the extension functions yourself.

Here is an example of how you might do the Upper Case function. This uses javascript within the XSLT to do the function.

<?xml version= 1.0 ?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:user="http://mycompany.com/mynamespace">

<msxsl:script language="javascript" implements-prefix="user">
   function uppercase(textToConvert) 
   {
      return textToConvert.toUpperCase();
   }
</msxsl:script>

<xsl:template match="text()">
   <xsl:value-of select="user:uppercase(string(.))"/>
</xsl:template>

</xsl:stylesheet>

What you could do, is put all the script functions in their own XSLT sheet, and include it in all your own XSLT stylesheets.

How complicated this turns out to be, depends on how many XPath2.0 functions you have used.

问题回答

Well, IMHO, you r a bit stuck. MSXML, does not implement XSLT 2.0 and XPath 2.0. So basically you are left with three options:

  1. Try to convince you supperiors that they should provide support for another XSLT processor like Saxon.NET.
  2. Reimplement all the functions you need using microsoft s msxsl:script function. This should prove difficult and leaves you with a dependency with the Microsoft parser. Furthermore, it only convers the XPath functions - the XSLT 2.0 functionality is not considered here.
  3. Reimplement your stylesheets using XSLT 1.0.

Personally, I guess that ony option 1 and 3 are feasible.





相关问题
When test hanging in an infinite loop

I m tokenising a string with XSLT 1.0 and trying to prevent empty strings from being recognised as tokens. Here s the entire function, based on XSLT Cookbook: <xsl:template name="tokenize"> ...

quick xslt for-each question

Let s say I have an XML document that has this: <keywords> <keyword>test</keyword> <keyword>test2</keyword> <keyword>test3</keyword> <keyword>test4</...

XSLT Transform XML with Namespaces

I m trying to transform some XML into HTML using XSLT. Problem: I can t get it to work. Can someone tell me what I m doing wrong? XML: <ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/...

XSLT output to HTML

In my XSLT file, I have the following: <input type="button" value= <xsl:value-of select="name">> It s an error as it violates XML rule. What I actually want is having a value from an ...

Mangling IDs and References to IDs in XML

I m trying to compose xml elements into each other, and the problem I am having is when there s the same IDs. Basically what I need to do is mangle all the IDs in an xml file, as well as the ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签