views:

23

answers:

1

Hi guys,

I'm new to C++ and inherited the following code that is supposed to transform the given XML using the XSLT file to just spit out the text values.

It loads both the XML and XSLT fine and the transformnode() call returns success but no transformation has been applied. The original output at the bottom contains the original XML intact .

It is using MSXML 3.0. I've used Xselerator to validate that the XSLT is valid and works (i.e. the string "This is a test message.." is returned).

Here is the code (minus all the error handling):

IXMLDOMNode *m_pXslt;

ESSXsltData::Initialise(void)
{
    IUnknown *l_pUnknown = NULL;
    IXMLDOMDocument *l_pXSLDocument = NULL;

HRESULT hr = CoCreateInstance(__uuidof(DOMDocument), NULL, CLSCTX_ALL, IID_IUnknown, (LPVOID *)&l_pUnknown);
hr = l_pUnknown->QueryInterface(IID_IXMLDOMDocument,(LPVOID *)&l_pXSLDocument);
CString l_sFileName(RetrieveXsltFileName().c_str() );
hr = l_pXSLDocument->load(l_vFileName, &l_bSuccess);

hr = l_pXSLDocument->QueryInterface(IID_IXMLDOMNode, (LPVOID *)(&m_pXslt) );
}

HRESULT ESSXsltData::ApplyXslt(const char *p_pszESSXml, std::vector< std::string > &p_CommentLines)
{
    IUnknown *l_pUnknown = NULL;
    IXMLDOMDocument *l_pDocument = NULL;


if (p_pszESSXml)
{
    VARIANT_BOOL l_bSuccess;
    HRESULT hr = CoCreateInstance(__uuidof(DOMDocument), NULL, CLSCTX_ALL, IID_IUnknown, (LPVOID *)&l_pUnknown);
    hr = l_pUnknown->QueryInterface(IID_IXMLDOMDocument,(LPVOID *)&l_pDocument);

    hr = l_pDocument->loadXML(CComBSTR(p_pszESSXml) , &l_bSuccess);
    hr = l_pDocument->QueryInterface(IID_IXMLDOMNode, (LPVOID *)(&m_pXslt) );

    BSTR l_bsOutput = NULL;
    hr = l_pDocument->transformNode(m_pXslt, &l_bsOutput);

    COLE2T l_AsciiOutput(l_bsOutput);
    log << "AsciiOutput: " << l_AsciiOutput << "\n"; 
}
}

The p_pszESSXml string is:

<ESS><Message>This is a test message...</Message></ESS>

The XSLT is:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="text" indent="yes"/>
    <xsl:template match="ESS">
        <xsl:apply-templates select="Message"/>
    </xsl:template>
    <xsl:template match="Message">
        <xsl:value-of select="."/>
    </xsl:template>
</xsl:stylesheet>
A: 

Fixed it.

It was reassigning m_pXslt to equal the XML is was supposed to be validating.

Someone has been copying and pasting.

TerryB