2010-09-03 79 views
1

我是C++的新手,並且繼承了下面的代碼,它應該使用XSLT文件轉換給定的XML,以便將文本值吐出。C++ XLST轉換不能使用MSXML 3.0

它加載了XML和XSLT,並且transformnode()調用返回成功,但沒有應用轉換。底部的原始輸出包含完整的原始XML。

它使用的是MSXML 3.0。我已經使用Xselerator來驗證XSLT是否有效並且有效(即返回字符串「This is a test message ..」)。

下面是代碼(減去所有的錯誤處理):

<?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> 

回答

0

固定它:

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"; 
} 
} 

的p_pszESSXml字符串是:

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

的XSLT是。

它正在重新分配m_pXslt以等於XML應該被驗證。

有人一直在複製和粘貼。