Subject: Dynamic processing using Perl From: "GRUBB,GARY (A-Sonoma,ex1)" <gary_grubb@xxxxxxxxxxx> Date: Thu, 30 Nov 2000 23:56:59 -0500 |
Hi there, I am new to XML and have been feverishly studying the subject this last two weeks. Here is the question of the hour: I apologize for the length, but I want to present the problem in detail. I have written a Perl CGI script (proof of concept) that dynamically creates a .xsl file and then reads in the .xml file and outputs it directly to the browser. Following is the text of the resulting .xsl file: <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <HTML> <HEAD version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <TITLE>test4</TITLE> </HEAD> <BODY> <TABLE BORDER="0" width="100%"> <xsl:for-each select="/TEST1/QUESTION[1]"> <TR> <TH colspan="2" width="100%" align="left"><xsl:value-of select="@TEXT"/></TH> </TR> <xsl:for-each select="./CHOICE"> <TR> <TD width="100%"> <xsl:value-of select="."/> </TD> </TR> </xsl:for-each> </xsl:for-each> </TABLE> </BODY> </HTML> </xsl:template> </xsl:stylesheet> Here is the output back to the browser via CGI: Content-type: text/html <?xml version = "1.0"?> <?xml:stylesheet type="text/xsl" href=".\test4.xsl"?> <TEST1> <QUESTION ID="1" TEXT="If your Oracle instance dies, what should you do?"> <CHOICE value="true">Call an Oracle DBA</CHOICE> <CHOICE value="false">Call a plummer</CHOICE> <CHOICE value="false">Call a doctor</CHOICE> <REFERENCE> Read your Oracle DBA Handbook, Dummy! </REFERENCE> </QUESTION> <QUESTION ID="2" TEXT="If your boss tells you to become an Oracle DBA, what should you do?"> <CHOICE value="false">Cuss him/her out</CHOICE> <CHOICE value="true">Tell your wife, I only want you to be happy!</CHOICE> <CHOICE value="false">Slit your wrists</CHOICE> <CHOICE value="false">Bend over</CHOICE> <REFERENCE> The Married Mans Guide </REFERENCE> </QUESTION> <QUESTION ID="3" TEXT="How much will you get paid to be an Oracle DBA?"> <CHOICE value="false">100,000 pesos</CHOICE> <CHOICE value="false">Million franks</CHOICE> <CHOICE value="true">Not enough!</CHOICE> <CHOICE value="false">Hey buddy, can you spare me some change?</CHOICE> <REFERENCE> jobs.com </REFERENCE> </QUESTION> </TEST1> What I expected was the XML code would be read by the browser (MS IE5.0) and the result would be the following: If your boss tells you to become an Oracle DBA, what should you do? Cuss him/her out Tell your wife, I only want you to be happy! Slit your wrists Bend over Instead I get this output: Call an Oracle DBA Call a plummer Call a doctor Read your Oracle DBA Handbook, Dummy! Cuss him/her out Tell your wife, I only want you to be happy! Slit your wrists Bend over The Married Mans Guide 100,000 pesos Million franks Not enough! Hey buddy, can you spare me some change? jobs.com Here is the Perl code: $| = 1; #Turn off buffering $question = 1; print "Content-type: text/html\n\n"; # Here text $xsl=<<XSL; <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <HTML> <BODY> <TABLE BORDER="0" width="100%"> <xsl:for-each select="/TEST1/QUESTION[$question]"> <TR> <TH colspan="2" width="100%" align="left"><xsl:value-of select="\@TEXT"/></TH> </TR> <xsl:for-each select="./CHOICE"> <TR> <TD width="100%"> <xsl:value-of select="."/> </TD> </TR> </xsl:for-each> </xsl:for-each> </TABLE> </BODY> </HTML> </xsl:template> </xsl:stylesheet> XSL # End of here text $xmlfile = "n:\\public_html\\programming\\XML\\test4.xml"; $xslfile = "n:\\public_html\\programming\\XML\\test4.xsl"; open(XSL,">$xslfile") or die "Cannot open << $xslfile >> : $!\n"; # Write to the XSL file print XSL $xsl; close (XSL); # Open the XML document for reading open(XML,"<$xmlfile") or die "Cannot open << $xmlfile >> : $!\n"; # Simply write it to the output while (<XML>) { print $_; } close (XML); (1) This sounds like a reasonble thing to do... why doesn't it work? (2) I have seen where CSS instructions can be embedded directly in an XML document. Is this possible with XSL instructions? If so, How? I searched the FAQ and possibly the following applies... >From http://www.dpawson.co.uk/xsl/nono.html item 10 the answer to my question sounds like NO. Thanks for taking the time to help me out! Regards, Gary Grubb Agilent Technologies Oracle DBA XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: parameter in path, Kay Michael | Thread | RE: Dynamic processing using Perl, Kay Michael |
parameter in path, Frank Hess | Date | Re: CSS (via entities), Miloslav Nic |
Month |