   
transformNode()
Is a member of:
|
DOMDocument
XMLDOMNode
XMLDOMAttribute
XMLDOMCDATASection
XMLDOMComment
XMLDOMDocumentFragment
XMLDOMDocumentType
XMLDOMElement
XMLDOMEntity
XMLDOMEntityReference
XMLDOMNotation
XMLDOMProcessingInstruction
XMLDOMText
XTLRuntime
|
Syntax
strVAlue = objDOMDocument.transformNode(strStylesheet)
Remark
The transformNode() method applies a stylesheet to the current Node and its child Nodes. It returns this data in a string, which is very useful for when you want to pass your data back as HTML (which means that your XSL file needs to convert your XML data to HTML):
strValue = objDOMDocument.transformNode(strStylesheet)
The string strValue will contain the contents to transform the Node into the required string. For more information, see chapter 5, "XSL-adding style to XML."
Example
The following example shows the string from the transformed Node being passed back using the transformNode() method. We use people2.xml to demonstrate the
transformNode() method.
Our XSL example looks as follows:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD>Name</TD>
<TD>Address</TD>
<TD>Tel</TD>
<TD>Fax</TD>
<TD>Email</TD>
</TR>
<xsl:for-each select="PEOPLE/PERSON">
<TR>
<TD><xsl:value-of select="NAME"/></TD>
<TD><xsl:value-of select="ADDRESS"/></TD>
<TD><xsl:value-of select="TEL"/></TD>
<TD><xsl:value-of select="FAX"/></TD>
<TD><xsl:value-of select="EMAIL"/></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
The code is:
Dim objXMLStyle As New DOMDocument
Dim objDOMDocument As New DOMDocument
Dim strXMLFromXSL As String
Call objDOMDocument.Load("http://localhost/xmlcode/people2.xml")
Call objXMLStyle.Load("http://localhost/xmlcode/people.xsl")
strXMLFromXSL = objDOMDocument.transformNode(objXML-Style.documentElement)
The strXMLFromXSL string returns the following HTML:
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD>Name</TD>
<TD>Address</TD>
<TD>Tel</TD>
<TD>Fax</TD>
<TD>Email</TD>
</TR>
<TR>
<TD>Mark Wilson</TD>
<TD>911 Somewhere Circle, Canberra, Australia</TD>
<TD>(++612) 12345</TD>
<TD>(++612) 12345</TD>
<TD>markwilson@somewhere.com</TD>
</TR>
<TR>
<TD>Tracey Wilson</TD>
<TD>121 Zootle Road, Cape Town, South Africa</TD>
<TD>(++2721) 531 9090</TD>
<TD>(++2721) 531 9090</TD>
<TD>Tracey Wilson@somewhere.com</TD>
</TR>
<TR>
<TD>Jodie Foster</TD>
<TD>30 Animal Road, New York, USA</TD>
<TD>(++1) 3000 12345</TD>
<TD>(++1) 3000 12345</TD>
<TD>Jodie Foster@somewhere.com</TD>
</TR>
<TR>
<TD>Lorrin Maughan</TD>
<TD>1143 Winners Lane, London, United Kingdom</TD>
<TD>(++94) 17 12345</TD>
<TD>++94) 17 12345</TD>
<TD>Lorrin Maughan@somewhere.com</TD>
</TR>
<TR>
<TD>Steve Rachel</TD>
<TD>90210 Beverly Hills, California, United States of America</TD>
<TD>(++1) 2000 12345</TD>
<TD>(++1) 2000 12345</TD>
<TD>Steve Rachel@somewhere.com</TD>
</TR>
</TABLE>
</BODY>
</HTML>    
This manuscript is an abridged version of a chapter
from the Manning
Publications book XML
Programming with VB and ASP. This chapter looks at the Microsoft DOM objects. NOTE: Most images have been removed to increase speed and many of the code comments have also been removed for presentation. Please purchase the book to enjoy the full experience of all the chapters with images and code comments!
|