Same prefix for an ext func + namespace
Added by Anonymous almost 16 years ago
Legacy ID: #6390303 Legacy Poster: David Lee (daldei)
Using Saxon XPath, is there a way to use the same prefix for an external function and for a namespace/URL. for example, suppose I want an external function p:system-property() say using programatically declareNamespace("p" , "java:my.class.Util" ); and also match a node from a namespace using the prefix p: such as <p:declare-step xlmns:p="http://www.xproc.org/steps"> Is it possible to bind the same prefix to both an external function and to a xml namespace URI ? here's why I'm trying to do this silly thing. http://markmail.org/search/?q=list:xproc-dev#query:list%3Axproc-dev%20from%3A%22David%20A.%20Lee%22+page:1+mid:hxauvaeu4r5zes3h+state:results To my reading of the xproc specs it seems to be required ,or atleast implied. but I'm a little fuzzy about the xpath specs as to if its possible, crazy, or obvious. -David
Replies (2)
RE: Same prefix for an ext func + namespace - Added by Anonymous almost 16 years ago
Legacy ID: #6432498 Legacy Poster: David Lee (daldei)
Any comments on this ? Here's a concrete example I cooked up from trying to implement xproc with saxon. Looking into this further, I am coming to the conclusion that extension functions should NOT share the same prefix as any schema being processed by the processor. For example is this input document to xproc pipeline parsable. Assuming it is a reqirement that the same prefix be used for the xprc pipeline (and child) elements as it is for the external function "base-uri' <p:pipeline 'xmlns:p=http://www.w3.org/ns/xproc'> <p:identity/> </p:pipeline> By this xproc pipeline <p:pipeline 'xmlns:p=http://www.w3.org/ns/xproc'> <p:string-replace match="p:pipeline"> <p:with-option name="replace" select="concat('"',p:base-uri(//p:identity[1]),'"')" </p:string-replace> </p:pipeline> note the use of the same prefix in replace, the function and the argument I don't believe this is possible with saxon, but I'd appreciate an opinion. If its possible could you suggest a method to declare an external function that is bound to the same prefix as an in-scope element in XPath. Thank you !
RE: Same prefix for an ext func + namespace - Added by Anonymous almost 16 years ago
Legacy ID: #6447184 Legacy Poster: Michael Kay (mhkay)
By default, mappings between URIs of external function names and the Java classes that implement the function are established by the class net.sf.saxon.functions.JavaExtensionLibrary. This has a few standard mappings built in, for the Saxon and EXSLT function namespaces, and if the URI is not one of these, then it tries to transform it into a Java class name directly (for example the URI java:java.lang.System becomes the Java class java.lang.System). You can register additional "known URIs" by calling the method javaExtensionLibrary.declareJavaClass(uri, theClass) You can get hold of the JavaExtensionLibrary by calling Configuration.getExtensionBinder(). This returns a FunctionLibrary, which will always be a JavaExtensionLibrary unless you called setExtensionBinder() to set it to something different. So yes, with a bit of configuration setting you can associate an arbitrary namespace URI with your extension functions. The only restriction, if you use this mechanism, is that all the functions in one namespace must map to methods in one Java class. (If you replace the JavaExtensionLibrary with something of your own invention, you can even get around this restriction).
Please register to reply