0

I am currently starting with win32com package. I have XSL file where I am using COM object programmed in Python:

<xsl:value-of select="plugin:GetTest(.)"/>

XSL transformation is done using MSXML2 XSL processor and python COM object is injected using addObject method. Implementation of the GetTest method is as follows:

    def GetTest(self, obj):
        IID_IXMLDOMNode = IID("{2933BF80-7B36-11d2-B20E-00C04F983E60}")
        try:
            node = win32com.client.Dispatch(obj, None, IID_IXMLDOMNode)
            #node = obj.QueryInterface(IID_IXMLDOMNode)
            return node.get_text()
        except Exception as e:
            return format_exc()

The obj argument has type PyIDispatch. In order to work with my IXMLDOMNode node interface I have to obtain it somehow, right? However, the uncommented approach fails with

AttributeError: <unknown>.get_text

And the commented approach fails with

obj.QueryInterface(IID_IXMLDOMNode)<\u000d>pywintypes.com_error: (-2147467262, 'No such interface supported'

Can anybody has suggestion what am doing wrong? Thanks in advance.

Patrik Polakovic
  • 542
  • 1
  • 8
  • 20
  • 2
    I have never used MSXML with Python so I can't assess the Python part of the code but as far as I remember from JScript or VBScript when you use e.g. `foo:method(.)` on the XSLT side you don't pass a single node to the method but rather a selection https://msdn.microsoft.com/en-us/library/ms759171(v=vs.85).aspx so you might want to try whether your Python code can be adapted to cast to a selection and not a node. – Martin Honnen Mar 16 '17 at 17:28
  • Thanks. You are right, the _obj_ is DOM selection – Patrik Polakovic Mar 17 '17 at 11:29

1 Answers1

0

I had two mistakes in the code, firstly, the obj is not selected node but DOM selection (thanks Martin Honnen), secondly, IXMLDOMNode hasn't _get_text_ method

def GetTest(self, obj):
    try:
        selector = win32com.client.Dispatch(obj, None, IID_IXMLDOMSelection)

        out = []

        for node in selector:
            out.append(node.nodeName)

        return ", ".join(out)
    except Exception as e:
        return format_exc()
Patrik Polakovic
  • 542
  • 1
  • 8
  • 20