July 05, 2008
For ColdFusion hosting try HostMySite.com. |
Home /
Groups /
ColdFusion Talk (CF-Talk)
ColdFusion , XML, XSLT, XPath and XHTML
I am attempting to use the CF xml functionality to parse up an xhtmlIan Skinner 05/13/08 10:43 A Hi Ian,Dominic Watson 05/13/08 11:06 A Dominic Watson wrote:Ian Skinner 05/13/08 11:17 A I'm not sure if this will work for you, but it may help:Dawson, Michael 05/13/08 12:12 P > How would I use this second name space in a ColdFusion xmlSearch()Dominic Watson 05/13/08 01:10 P > aXPathSearchResults = oXml.Search('//xHtml:Dominic Watson 05/13/08 01:11 P I found some Python discussions on XPath and XHTML that indicated I needIan Skinner 05/13/08 11:11 A I am attempting to use the CF xml functionality to parse up an xhtml document and I can not seem to get any results. Is there something about this world I am not getting? No matter how I try to reference any xml nodes I just get a blank result. spb.cfm -------- <cfsilent> <cfsetting showdebugoutput="no"> <cfhttp url="http://www.spb.ca.gov/jobs/exams/exam_start.htm" resolveurl="yes"/> <cfset xmlObj = xmlParse(cfhttp.FileContent)> <cffile action="read" file="#getDirectoryFromPath(getCurrentTemplatePath())#spb.xsl" variable="xslt"> </cfsilent><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>SPB</title> </head> <body> <cfoutput>#htmlCodeFormat(xmlTransform(xmlObj,xslt))#</cfoutput> <cfdump var="#xmlSearch(xmlObj,'//option')#"> <hr color="#000000" size="10" /> <cfoutput>#htmlCodeFormat(cfhttp.FileContent)#</cfoutput> </body> </html> spb.sxl ------- <?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="http://www.spb.ca.gov/jobs/exams/exam_start.htm" --><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> <!ENTITY copy "©"> <!ENTITY reg "®"> <!ENTITY trade "™"> <!ENTITY mdash "—"> <!ENTITY ldquo "“"> <!ENTITY rdquo "”"> <!ENTITY pound "£"> <!ENTITY yen "¥"> <!ENTITY euro "€"> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="utf-8"/> <xsl:template match="/"> <xsl:value-of select="//option" /> </xsl:template> </xsl:stylesheet> Hi Ian, This line creates a default namespace for the xml which may be your problem: > <html xmlns="http://www.w3.org/1999/xhtml"> To match any node in an xml document with a default namespace, you will need to add the default namespace to your xpath which is just a colon: <xsl:value-of select="//:option" /> HTH Dominic -- Blog it up: http://fusion.dominicwatson.co.uk Dominic Watson wrote: ----- Excess quoted text cut - see Original Post for more ----- Yes, I did discover that this was a name space issue. ----- Excess quoted text cut - see Original Post for more ----- I tried this solution and I get this error: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: Prefix must resolve to a namespace: But adding a another name space parameter to my xsl seems to work well. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"> ... <xsl:for-each select="//xhtml:option"> As I asked in my other post. How does one make use of multiple name spaces like this in the ColdFusion xml functions such as xmlSearch? I'm not sure if this will work for you, but it may help: http://www.talkingtree.com/blog/index.cfm/2005/11/18/XmlSearchNoNameName space Read through the comments for the xmlSearch wildcards. You may be able to skip over the namespaces with the wildcards. m!ke Dominic Watson wrote: > Hi Ian, > > This line creates a default namespace for the xml which may be your problem: > >> <html xmlns="http://www.w3.org/1999/xhtml"> >> Yes, I did discover that this was a name space issue. ----- Excess quoted text cut - see Original Post for more ----- I tried this solution and I get this error: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: Prefix must resolve to a namespace: But adding a another name space parameter to my xsl seems to work well. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"> .... <xsl:for-each select="//xhtml:option"> As I asked in my other post. How does one make use of multiple name spaces like this in the ColdFusion xml functions such as xmlSearch? > How would I use this second name space in a ColdFusion xmlSearch() > function? This is a tricky one. For xslt, what you are doing there is mapping any namespaces in the target xml with a prefix. From then on, using the prefix in your xslt will work great. For XmlSearch however, there is no ColdFusion tool for mapping namespaces to prefixes so you can only use the ':' default namespace prefix. If you have more than one default namespace in your xml, you are left without a paddle (using ':' won't work). Enter betterXml. I have made a couple of components to utilize xpath better in coldfusion (mainly for maintaining xml files but useful in other situations). The xmlReader component has a MapNamespace method that does what it says on the tin. You could do: oXml = createObject('component', 'betterXml.betterXmlReader').init(xmlFile); oXml.MapNamespace('http://www.w3.org/1999/xhtml', 'xHtml'); aXPathSearchResults = oXml.Search('//xHtml: Check out my blogpost on this: http://fusion.dominicwatson.co.uk/2008/03/xmlsearch-and-default-namespaces.html The project is on riaforge: http://betterxml.riaforge.org HTH Dominic -- Blog it up: http://fusion.dominicwatson.co.uk > aXPathSearchResults = oXml.Search('//xHtml: Should be: aXPathSearchResults = oXml.Search('//xHtml:option'); -- Blog it up: http://fusion.dominicwatson.co.uk I found some Python discussions on XPath and XHTML that indicated I need another name space in my xslt. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml"> <xsl:output method="html" encoding="utf-8"/> <xsl:template match="/"> <xsl:for-each select="//xhtml:option"> <xsl:value-of select="." /> </xsl:for-each> </xsl:template> </xsl:stylesheet> This seems to be working. Is there any advice for me on this concept? How would I use this second name space in a ColdFusion xmlSearch() function?
|
Mailing Lists
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||