Transforming EADs into HTML using Coldfusion
Aug 30th, 2006 by Karen
Remember how I said I was having problems using the XmlTransform function in Coldfusion to transform my EADs into HTML? My original solution was to alter the XML document. Not desirable, but I couldn’t find another way to deal with it. Well, here is another possible solution I found, which involves stripping the stylesheet and DOCTYPE from the XML document before it is passed to the XML parse. So here is what my code looks like now that I’ve added the lines to strip the embedded XSLT, and DOCTYPE.
<cffile action="read" file="/path/to/xml/file.xml" variable="faidxml"> <cffile action="read" file="/path/to/xsl/file.xsl" variable="eadxsl"> <cfset faidxml =rereplacenocase(faidxml,"<\?xml:stylesheet[^>]*>","")> <cfset faidxml =rereplacenocase(faidxml,"<\!DOCTYPE ead PUBLIC[^>]*>","")> <cfset Transformed = xmlTransform(faidxml, eadxsl)>
This doesn’t alter the base XML file, but just removes the offending lines before the transform is executed. I could write it slightly differently to use full paths to reference my DTD but I can’t see the harm in just temporarily stripping this out before I do the transform. Doing it this way, I don’t have to have a copy of the ead.dtd on my server where as if I changed the files to have full paths I’d need to have the files. For me this is the easiest way to get around the fact that Coldfusion’s XML parser is dumb. Supposedly it is better in version 7.0 but I haven’t had time to upgrade our servers yet. In the meantime, this workaround has helped me move forward on this project.

