I am trying to get MSXML6 XSLT import (or include) functionality working for my app. I have looked everywhere for a solution to this and have found a number of references to people for whom it seems to be working so I'm thinking I must be doing something wrong but I can't figure out what it is.
Book.xml
<Book>
<Title>A Christmas Carol</Title>
<Author>Charles Dickens</Author>
<Binding>Hardcover</Binding>
<Price>14.99</Price>
<Comment/>
</Book>
DefaultRules.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="/Temp/Book.xsl"/>
<xsl:output method="text" indent="no"/>
<xsl:template match="/">
<xsl:apply-templates select="Book"/>
</xsl:template>
</xsl:stylesheet>
Book.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Book">
<xsl:text>Title: </xsl:text>
<xsl:apply-templates select="Title"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="Author"/>
<xsl:text> - $</xsl:text>
<xsl:apply-templates select="Price"/>
</xsl:template>
</xsl:stylesheet>
Proto.cpp
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
variant_t vResult;
LPCTSTR output = NULL;
MSXML2::IXMLDOMDocumentPtr pXml(__uuidof(MSXML2::DOMDocument60));
MSXML2::IXMLDOMDocumentPtr pXslt(__uuidof(MSXML2::FreeThreadedDOMDocument60));
MSXML2::IXSLTemplatePtr pTemplate(__uuidof(MSXML2::XSLTemplate60));
MSXML2::IXSLProcessorPtr pProcessor;
IStream *pOutStream;
// load xml file with data and xsl file to transform
// xml -> html
pXml->async = false;
pXml->load(_bstr_t("Book.xml"));
pXslt->resolveExternals = true;
pXslt->async = false;
pXslt->load(_bstr_t("/Temp/DefaultRules.xsl"));
pTemplate->stylesheet = pXslt;
pProcessor = pTemplate->createProcessor();
CreateStreamOnHGlobal(NULL, TRUE, &pOutStream);
pProcessor->put_output(_variant_t(pOutStream));
pProcessor->put_input(_variant_t((IUnknown*)pXml));
pProcessor->transform();
//get results of transformation and print them to stdout
HGLOBAL hg = NULL;
pOutStream->Write((void const*)"\0\0", 2, 0);
GetHGlobalFromStream(pOutStream, &hg);
output = (LPCTSTR)GlobalLock(hg);
wprintf(L"%s", output);
GlobalUnlock(hg);
//release before CoUninitialize()
pXml.Release();
pXslt.Release();
pTemplate.Release();
pProcessor.Release();
CoUninitialize();
getchar();
return 0;
}
The (correct) output I get from an XML tool (EditiX) is
Title: A Christmas Carol
Charles Dickens - $14.99
The (incorrect) output that I get from MSXML6 transform is
A Christmas CarolCharles DickensHardcover14.99
It looks like the file specified for inclusion isn't being imported/included so I'm just getting the default template results although I don't get any error messages. As you can see, I am setting the resolveExternals flag to true (new for MSXML6). I have also tried loading it from the current folder as well as a specific folder (the above code uses /Temp). I have also tried using both xsl:import and xsl:include. The solution always works in the XML tool but always gives the incorrect result using the above code and MSXML6. I am using Windows 10 if that could be related.