Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2003, 10:00 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default IXSLProcessor output

I understand that the output of the transform method could be to any IStream supporting object. I am attempting to get the output into a DOMDocument but I am failing miserably. All I can get is the string output. Anyone have a small working example?


Love,
Michael
 
Old July 20th, 2003, 03:19 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you provide an example that has not worked?

--

Joe
 
Old July 20th, 2003, 02:56 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you in advance for your time.

If I comment out the line where the output is set, I can see that the transform is working by readin the text from output. I obviously need to do something to the document that recieves the output.

try
{
    HRESULT hr;
    IXSLTemplatePtr xsltemplate;
    IXMLDOMDocumentPtr xsldocument;
    // create a document to hold the xslt template
    hr = xsltemplate.CreateInstance("Msxml2.XSLTemplate");
    hr = xsldocument.CreateInstance("Msxml2.FreeThreadedDOM Document");

    // load the transform
    xsldocument->async = false;
    xsldocument->load("test.xsl");
    xsltemplate->stylesheet = xsldocument;

    // load the xml to be transformed
    IXMLDOMDocumentPtr xml;
    hr = xml.CreateInstance("Msxml2.FreeThreadedDOMDocument ");
    xml->async = false;
    xml->load("test.xml");

    // create a processor
    IXSLProcessorPtr proc;
    proc = xsltemplate->createProcessor();

    // create a document to be the output
    IXMLDOMDocumentPtr resultxml;
    hr = resultxml.CreateInstance("Msxml2.FreeThreadedDOMDo cument");

    // do the trasnform
    proc->input = variant_t((IUnknown*)xml);
    proc->setStartMode("versions", "");
    proc->output = variant_t((IUnknown*)resultxml);
    proc->transform();

        // empty messagebox
    ::MessageBox(0,resultxml->xml,0,0);

    }
    catch(_com_error e)
    {
        ::MessageBox(0,e.Description(),"exception",0);
    }


// test.xsl
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rs='urn:schemas-microsoft-com:rowset' xmlns:z='#RowsetSchema' version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="/" mode="versions">
<xsl:for-each select='xml/rs:data/z:row'>
    <version>
        <object type='string'><xsl:value-of select='@object'/></object>
        <version type='string'><xsl:value-of select='@version'/></version>
    </version>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>


// test.xml
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
 xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
 xmlns:rs='urn:schemas-microsoft-com:rowset'
 xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
 <s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'
  rs:ReshapeName='DSRowset1'>
  <s:AttributeType name='object' rs:number='1' rs:writeunknown='true'>
   <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='128'
    rs:maybenull='false'/>
  </s:AttributeType>
  <s:AttributeType name='version' rs:number='2' rs:writeunknown='true'>
   <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='50'
    rs:maybenull='false'/>
  </s:AttributeType>
  <s:extends type='rs:rowbase'/>
 </s:ElementType>
</s:Schema>
<rs:data>
 <z:row object='Aggregate' version='2.0'/>
 <z:row object='BackPrintLines' version='2.0'/>
 <z:row object='Config' version='3.0'/>
 <z:row object='Customer' version='6.0'/>
 <z:row object='FlowController' version='2.0'/>
 <z:row object='FlowControlRecipe' version='2.0'/>
 <z:row object='Frame' version='6.0'/>
 <z:row object='FulfillmentStatus' version='6.0'/>
 <z:row object='Image' version='7.0'/>
 <z:row object='ImageNode' version='6.0'/>
 <z:row object='ImageSource' version='5.0'/>
 <z:row object='Item' version='2.0'/>
 <z:row object='Logos' version='3.0'/>
 <z:row object='OrderEntryData' version='11.0'/>
 <z:row object='Orders' version='9.0'/>
 <z:row object='PaperPack' version='1.0'/>
 <z:row object='PicturePackage' version='4.0'/>
 <z:row object='Preference' version='1.0'/>
 <z:row object='Product' version='7.0'/>
 <z:row object='Rendition' version='3.0'/>
 <z:row object='TextLines' version='4.0'/>
 <z:row object='Versions' version='2003.02.1-INT-001'/>
</rs:data>
</xml>



Love,
Michael
 
Old July 21st, 2003, 01:13 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

For this to work the output has to be a valid xml document, your output doesn't have an all encompassing document element.

--

Joe
 
Old July 21st, 2003, 08:52 AM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. This would qualify as a stupid mistake.


Love,
Michael
 
Old July 21st, 2003, 09:10 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

We've all done worse...
I was a bit surprised in some ways that it let you construct an invalid document when you specify output="xml".


--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output to text bonekrusher XSLT 4 November 25th, 2007 01:06 PM
tell me the output abdul_owiusa C# 3 May 10th, 2007 04:25 AM
Output should appear in Mozila instead of IE anujrathi ASP.NET 1.0 and 1.1 Professional 2 August 30th, 2006 09:47 AM
Output Difference wolftrap1 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 January 4th, 2004 05:44 PM
how to get this output? Haroldd SQL Language 2 July 16th, 2003 07:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.