Mellor: XML - Learning by Example.




I'm having difficulty putting links into my XSL files. In the XML file I have:


and in the stylesheet:

<script language="javascript">
Descipt = '<xsl:value-of select="link"/>'
document.write("<a href="+Descript+">Download publication in PDF format.</a>");

But this only works in Explorer, not in Firefox.

Use xsl:element & attribute for the , thus:

<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="link"/>
Download publication in PDF format.

This will work for both Firefox and Explorer, but note that
www.opera.com/docs/specs/opera8/index.dml states that "Opera does not support XSL formatting objects, and neither does it natively support XSLT transformations."

I can't get your example A2 about the AURAL media directive to work.

CSS2-enabling in 5+ browsers has not been implemented accross the board. Download and install the plug in from http://www.voicewebsolutions.net/

How do I write processing instructions in XML. I am thinking mainly of my "print" application in PHP

XML processing instructions contain information for the application. Processing instructions are not part of the CDATA and XML should pass these on to the application unchanged. The general syntax is:

<?TargetApp instructions?>

In your case you may like to try:

<?php print "put your text string here"; ?>

This should be passed on as:

ProcessingInstructionHandler ($parser, "php", string "print \"put yourtext string here\";");

How does PHP parse XML - I'm getting question marks ( ? ) returned

Firstly, XML support is not available by default. However PHP can support a set of functions, implemented using Expat. The XML parser in PHP is streams-based, so the XML document is fed in in chunks. The parser will not check for validity (only well-formed-ness). If PHP encounters characters in the parsed XML document which are not in the chosen Target Encoding, then it will return question mark ( ? ) characters.

Specify ISO-8859-1 and use an XML document containing only ASCII, and if that reduces the effect, then change Target Encoding to your ISO language code.

How do I get an XML parser ? I'm interested in development work.

There are several freeware and shareware parsers available, mostly written in Java. You can also use Microsofts parser (which comes with IE5).

If you do not want to upgrade, then you can continue with IE4 and install the parser on your PC. The parser can be downloaded from Microsoft.com (specifically, msdn.Microsoft.com/downloads/tools/xmlparser/xmldl.asp)

The installed file is msxml.dll and is a COM component, so you can use it with ASP, VB, C++ or any other development tool which understands COM

If you are using Visual InterDev, then simply create a project reference to the Microsoft XML version X.X type library, and use the IntelliSense technology to see the property and method calls available.

How do I display XML as HTML in browsers other than IE5

Transforming data with client-side XSL is convenient, but for browser compatibility (especially for down-level browsers) you must perform the XSL transform on the server.

Install a server (e.g. Personal Web Server 4) and work in the C:\inetpub\wwwroot directory. Write:

<%@ Language="VBScript" %>

XSLFile= Server.MapPath("my.xsl")
Set DomDoc=Server.CreateObject("Microsoft.XMLDom")
DomDoc.Load (XMLFile)
Set StyleDoc=Server.CreateObject("Microsoft.XMLDom")
StyleDoc.Load (XSLFile)
Response.Write (DomDoc.transformNode(StyleDoc))

Save as my.asp and view in any browser (you will clearly need to put content into the XML and XSL files).

The key is the transformNode method, using the stylesheet reference as argument.

What is the ProgID for creating XMLDOM Document Objects ?

There are in all 6:

Microsoft.XMLDom is version dependent (not recommended), Microsoft.XMLDom 1.0 is version-independent. MSXML.DomDocument is the objects class name. However all 3 create the same ClassID {2933BF90-7B36-11D2-B20E-00C04F983E60}

The corresponding ProgIDs creating free-threaded DOMDocument objects (used for storing an object at Session or Application level) are:

Microsoft.FreeThreadedXMLDom (not recommended)

Microsoft.FreeThreadedXMLDom 1.0


What is WDDX ?

WDDX stands for Web Distributed Data eXchange and is an open, standards-based dialect of XML. WDDX is being pushed by Allaire for their Cold Fusion system (dynamic, database-driven web-sites). For more details see Allaires "Developer Exchange" www.allaire.com/developer/gallery.cfm and www.openwddx.org

One of the major benefits of using WDDX is that programmers can exchange structured data over the Web without having to use the XML natively. WDDX is what some call "XML middleware", where programming languages use it as a transport for their own native data

Do I have to write long Java strings every time I want to run XSLT

No, you don't need to use Java, and if you do, then write the command string to a command file (BAT under Windows or shell Script under UNIX) and run that instead. An example to run IBMs XML for Java parser could be (and this is all on one line):

java -classpath C:\xml4j\xml4j.jar;C:\xml4j\xml4jsamples.jar XJParse -p com.ibm.parsers.ValidatingSAXParser %1

Save this as myfile.bat. You can run from the command line, the %1 enables you to simply put the name of your file afterwards:

C:\>myfile myxmlfile.xml

Return to overview