Hi Dave,

Thanks a lot for your reply.

I could make it work.

My requirement was that the external functions' namespace would be the same
as that has been been mapped to the same prefix for the root document object.
(I doubt I am not very clear in stating the above !!)

I used the same namespace as that of the document objects', and then installed
the external functions. Also, I found that its working if I use 
installExternalFunctionGlobal()
instead of installExternalFunction(). Is this kind of usage okay ? Anyway my 
job is getting
done. Also, ElementPrefixResolverProxy is working when I use  
installExternalFunctionGlobal().
I guess its because the same namespace and prefix are getting used while 
installing the
functions and creating the document object.

Please provide your comments.

Thanks again for your inputs which enabled me to get the stuffs work.

Thanks,
Indrajit  


On Fri, 08 Jun 2007 David Bertoni wrote :
>Indrajit Bhattacharya wrote:
>>Hi Dave,
>>
>>I want to achieve the following:
>>
>>I have a XercesDOM document object. There is an XPath expression like the 
>>following, for
>>, say, one attribute's value: cube(id('id1')). Here, id() is the XPath 
>>function, id1 is the id of an element
>>whose value is, say, 10. Cube is a function that I want to implement. I have 
>>to get the result 1000
>>when this XPath expression is evaluated.
>>
>>Please note that I should not have to have any XSL file. Everything has to be 
>>done in-memory.
>>Also, I need not do any transform on the input document. Only what I need to 
>>do is get the XPath
>>expression evaluated to get the correct value.
>>
>>I have the following code. It returns correct value for id('id1'), but for 
>>cube(id('id1')) it throws
>>xalanc::XPathParserException exception.
>
>Yes, because XPath does not define a function called cube.  You need to map 
>your function's namespace to a particular prefix, and use that in the XPath 
>expression.  You can see how this works by looking at the stylesheet for the 
>sample you've copied.
>
>>
>>I will be grateful if you could please let me know where I am doing stuffs
>>wrong, and how to do it correctly to get the desired output.
>>
>>Code:
>>
>
>...
>
>...
>
>>
>>int foo(xercesc::DOMDocument *dom_document_, char* xpath, std::string& output)
>>{
>>            XMLPlatformUtils::Initialize();
>>       XalanTransformer::initialize();
>>       XPathEvaluator::initialize();
>>
>>                     {
>>                     // Create a XalanTransformer.
>>                     XalanTransformer     theXalanTransformer;
>>
>>                     const XalanDOMString     theNamespace(" ");
>
>A space is not a legal namespace URI.  It might work, but it might not. You 
>should choose a better URI.
>
>>
>>                                         
>> theXalanTransformer.installExternalFunction(
>>                          theNamespace,
>>                          XalanDOMString("cube"),
>>                          FunctionCube());
>>
>>                         XercesDOMSupport      theDOMSupport;
>>                     XercesParserLiaison  theParserLiaison(theDOMSupport);
>>
>>                         XalanDocument*  theDocument =
>>                       theParserLiaison.createDocument(
>>                           dom_document_,
>>                             true,
>>                             true,
>>                             true);
>>
>>                    XPathEvaluator  theEvaluator;
>>
>>                    const XalanElement* const  theRootElement =
>>                    theDocument->getDocumentElement();     
>>                    ElementPrefixResolverProxy 
>> thePrefixResolver(theRootElement);
>
>An element prefix resolver will not work, because you need to associate a 
>prefix for the cube function with the namespace you used when you installed 
>the extension function.  You will need to write your own PrefixResolver 
>implementation that can resolve the prefix you've chosen to the correct 
>namespace URI, or, if it can't, pass the request on to another PrefixResolver.
>
>Dave

Reply via email to