I am developing a dynamic XPATH function for a MS XSLT transform. I am running the transform under a VB.NET (4.5) wrapper:
Public Function evaluate1(Context As XPathNodeIterator, Expression As String) As XPathNodeIterator
Dim nsXmlNamespaceManager As XmlNamespaceManager
nsXmlNamespaceManager = New XmlNamespaceManager(Context.Current.NameTable)
Return Context.Current.Select(Expression, nsXmlNamespaceManager)
The function works with unqualified elements (no http: ), but if the namespace is used the "Namespace prefix 'http' is not defined." error is caught. I listed the contents of nsXmlNamespaceManager and see
I know I should be able to add a namespace to the nsXmlNamespaceManager, but that would not be a general solution. It would seem logical to find the @xmlns:* attributes on the XSLT and add those to nsXmlNamespaceManager (assuming I could pass a reference to some XSLT object that would allow me to navigate to the xsl:stylesheet node (or pass a nodeset of those attributes to the function)).
Anyway, the search results on this subject are getting a little thin and I wanted to know if anyone had ventured down this path before and what they did?
I found a round about solution, but think it would be nicer to find the information in the object model from the function arguments. The round about solution was to read the XSL document (XmlReader) and extract the <xsl:stylesheet xmlns: attributes and from those create a XmlNamespaceManager (and XmlNameTable). The XmlNamespaceManager was passed to the XSL Extension class constructor which places the value in a private class variable that is used in the .Select argument list. This makes the wrapper program have to read the XSL document twice, once to find the stylesheet element and close/reopen to pass to XslCompiledTransform. It works and now the extension function evaluate can accept XPath with namespace prefixes.
Last Visit: 31-Dec-99 18:00 Last Update: 16-Aug-17 14:45