Oracle8i Application Developer's Guide - XML
Release 3 (8.1.7)

Part Number A86030-01

Library

Solution Area

Contents

Index

Go to previous page Go to beginning of chapter Go to next page

Using XML Parser for Java, 22 of 22


XSL-T Processor and XSL Stylesheets

HTML Error in XSL

Question

I don't know what is wrong here. This is my news_xsl.xsl file:

<?xml version ="1.0"?>
<xsl:stylesheet  xmlns:xsl="http://www.w3.org/TR/WD-xsl">    
<xsl:template match="/"> 
 <HTML>
    <HEAD>
        <TITLE>   Sample Form    </TITLE>        
        </HEAD> 
     <BODY>
      <FORM>  
       <input type="text" name="country" size="15">    </FORM>                         
    </BODY> 
 </HTML>  
</xsl:template>
</xsl:stylesheet>

ERROR:End tag 'FORM' does not match the start tag 'input'. Line 14, Position 12           
</FORM>-
----------^news.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="news_xsl.xsl"?>
<GREETING/>

Answer

Unlike in HTML, in XML you must know that every opening/starting tag should have an ending tag. So even the input that you are giving should have a matching ending tag, so you should modify your script like this:

<FORM>
<input type="text" name="country" size="15"> </input>
</FORM> 

OR

<FORM>
<input type="text" name="country" size="15"/>
</FORM>

And also always remember, in XML the tags are case sensitive, unlike in HTML. So be careful.

Is <xsl:output method="html"/> Supported?

Question

Is the output method "html" supported inthe recent version of the XML/XSL parser?I was trying to use the <BR> tag with the<xsl utput method="xml"/> declaration butI got an XSLException error message indicating a not well-formed XML document. Then I tried the following output methoddeclaration: <xsl utput method="html"/>but I got the same result?!

Here's a simple XSL stylesheet I was using:

<?xml version="1.0"?> <xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl utput method="html"/>    
<xsl:template match="/">      <HTML>         <HEAD></HEAD>         <BODY>         
<P>           Blah blah<BR>           More blah blah<BR>         </P>         
</BODY>      </HTML>   </xsl:template>

My question is: "How do I use a not well-formed tags (like <IMG>, <BR>, etc.)in a XSL stylesheet?"

Answer

We fully support all options of <xsl utput> The problem here is that your XSL Stylesheet must be a well-formed XML document, so everywhere you are using the <BR> element, you need to use <BR/> instead.<xsl utput method="html"/> requests that when the XSLT Engine *writes out* the result of your transformation, is a proper HTML document. What the XSLT engine reads *in* must be well-formed XML.

Question 2

Sorry for jumping in on this thread, but I have a question regarding your reply. I have an XSL stylesheet that preforms XML to HTML conversion. Everything works correctly with the exception of those HTML tags that are not well formed. Using your example if I have something like:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
......
<input type="text" name="{NAME}" size="{DISPLAY_LENGTH}" maxlength="{LENGTH}">
</input>
......
</xsl:stylesheet>

It would render HTML in the format of

<HTML>......<input type="text" name="in1" size="10" maxlength="20"/>
......
</HTML>

While IE can handle this Netscape can not. Is there anyway to generate completely cross browser complient HTML with XSL?

Answer 2

If you are seeing:

<input ... />

instead of:

<input>

Then you are likely using the incorrect way of calling XSLProcessor.processXSL() since it appear that it's not doing the HTML output for you. Use:

void processXSL(style,sourceDoc,PrintWriter)

instead of:

DocumentFragment processXSL(style,sourceDoc)

and it will work correctly.

Netscape 4.0: Preventing XSL From Outputing <meta> Tag

Question

I'm using <xsl utput method="html" encoding="iso-8859-1" indent = "no" />. Is it possible to prevent XSL-T from outputting <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> in the head because Netscape 4.0 has difficulties with this statement. It renders the page twice.

Answer

The XSLT 1.0 Recommendation says in Section 16.2 ("HTML Output Method")...If there is a HEAD element, then the html output method should add a META element immediately after the start-tag of the HEAD element specifying the character encoding actually used.

For example:

<HEAD><META http-equiv="Content-Type" content="text/html; charset=EUC-JP">.

So any XSLT 1.0-compliant engine needs to add this.

Question 2

Netscape 4.0 has following bug:

When Mozilla hits the meta-encoding tag it stops rendering the page and does a refresh. So you experience this anoying flickering. So I probably have to do a replacement in the servlets Outputstream, butI don't like doing so. Are there any alternatives.

Answer 2

Only alternatives I can think of are:

Neither is pretty, but either one might provide a workaround.

XSL Error Messages

Question

Where can I find more info on the XSL error messages. I get the error XSL-1900 , exception occurred. What does this mean ? How can I find out what caused the exception ?

Answer

If you are using Java, you could write Exception routines to trap errors.Using tools such as JDeveloper also helps.

The error messages of our components are usually more legible. XSL-1900 indicates possible internal error or incorrect usage. Please post a code sample that produces this error including your sample XML and DTD file if applicable.

Generating HTML: "<" Character

Question

I am trying to generate an HTML form for inputting data using column names from the user_tab_columns table and the following XSL code:

<xsl:template match="ROW">
<xsl:value-of select="COLUMN_NAME"/>
<: lt;INPUT NAME="<xsl:value-of select="COLUMN_NAME"/>>
</xsl:template>

although 'gt;' is generated as '>' 'lt;' is generated as '#60;'. How do I generate the "<" character?

Comment

Using the following:

<xsl:text disable-output-escaping="yes">entity-reference</xsl:text>

does what I need.

HTML "<" Conversion Works in oraxsl but not XSLSample.java?

Question

I can't seem to display HTML from XML.In my XML file I store the HTML snippet in an XML tag:

<PRE>
<body.htmlcontent>
<&#60;table width="540" border="0" cellpadding="0" 
cellspacing="0">&#60;tr>&#60;td>&#60;font face="Helvetica, Arial" 
size="2">&#60;!-- STILL IMAGE GOES HERE -->&#60;img 
src="graphics/imagegoeshere.jpg"  width="200" height="175" align="right" 
vspace="0" hspace="7">&#60;!-- END STILL IMAGE TAG -->&#60;!-- CITY OR TOWN NAME 
GOES FIRST FOLLOWED BY TWO LETTER STATE ABBREVIATION -->&#60;b>City, state 
abbreviation&#60;/b> - &#60;!-- CITY OR TOWN NAME ENDS HERE -->&#60;!-- STORY 
TEXT STARTS HERE -->Story text goes here.. &#60;!-- STORY TEXT ENDS HERE 
-->&#60;/font>&#60;/td>&#60;/tr>&#60;/table>
</body.htmlcontent>
</PRE>

I use the following in my XSL:

<xsl:value-of select="body.HTMLcontent" disable-output-escaping="yes"/>

However, the HTML output

<PRE>&#60;</PRE>

is still outputted and all of the HTML tags are displayed in the browser. How do I display the HTML properly?

Comment

That doesn't look right. All of the < are #60; in the code with an ampersand in front of them. They are still that way when they are displayed in the browser.

Even more confusing is that it works withoraxsl, but not with XSLSample.java.

Answer

This makes sense. Here's why:

The former supports <xsl:output> and all options related to writing out output that might not be valid XML (including the disable output escaping). The latter is pure XML-to-XML tree returned, so no <xsl:output> or disabled escaping can be used since nothing's being output, just a DOM tree fragment of the result is being returned.


XSL-T Examples

Question

Is there any site which has good examplesor small tutorials on XSL-T?

Answer

This site is an evolving tutorialon lots of different XML/XSLT/XPath-related subjects:

http://zvon.vscht.cz/ZvonHTML/Zvon/zvonTutorials_en.html

XSL-T Features

Question

  1. Is there a list of features of the XSL-T that Oracle XDK implements?

  2. So the v2 parsers implement more features of the recommendation than IE5 ? My first impression supports this, the use of <xsl:choose... and <xsl:if... works with the v2 parser but gives strange messages with IE5.

Answer

  1. Our v2 parsers support the W3C Recommendation of w3c XSL-T version 1.0 at http://www.w3.org/TR/XSLT.

  2. You are correct. Ours is XSL-T Recommendation compliant.

Using XSL To Convert XML Document To Another Form

Question

I am in the process of trying to convert an xml document from one format to another by means of an xsl (or xslt) stylesheet. Before incorporating it into my java code, I tried testing the transformation from the command line:

 > java oracle.xml.parser.v2.oraxsl jwnemp.xml jwnemp.xsl newjwnemp.xml

The problem is that instead of returning the transformed xml file (newjwnemp.xml), the above command just returns a file with the xsl code from jwnemp.xsl in it. I cannot figure out why this is occurring. I have attached the two input files.

 <?xml version="1.0"?>
 <employee_data>
    <employee_row>
       <employee_number>7950</employee_number>
       <employee_name>CLINTON</employee_name>
       <employee_title>PRESIDENT</employee_title>
       <manager>1111</manager>
       <date_of_hire>20-JAN-93</date_of_hire>
       <salary>125000</salary>
       <commission>1000</commission>
       <department_number>10</department_number>
    </employee_row>
 </employee_data>

 <?xml version='1.0'?>
 <ROWSET xmlns:xsl="HTTP://www.w3.org/1999/XSL/Transform">
    <xsl:for-each select="employee_data/employee_row">
    <ROW>
       <EMPNO><xsl:value-of select="employee_number"/></EMPNO>
       <ENAME><xsl:value-of select="employee_name"/></ENAME>
       <JOB><xsl:value-of select="employee_title"/></JOB>
       <MGR><xsl:value-of select="manager"/></MGR>
       <HIREDATE><xsl:value-of select="date_of_hire"/></HIREDATE>
       <SAL><xsl:value-of select="salary"/></SAL>
       <COMM><xsl:value-of select="commission"/></COMM>
       <DEPTNO><xsl:value-of select="department_number"/></DEPTNO>
    </ROW>
    </xsl:for-each>
 </ROWSET>

Answer

This is occurring nearly 100%-likely because you have the wrong XSL namespace uri for your xmlns:xsl="..." namespace declaration.

If you use: xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

everything works.

If you use xmlns:xsl="-- any other string here --"

If will do what you're seeing.

Information on XSL?

Question

I cannot find anything about using XSL. Can you help? I would like to get an XML and XSL file to show my company what thay can expect from this technology. XML alone is not very impressive for users.

Answer

A pretty good starting place for XSL is the following page:

http://metalab.unc.edu/xml/books/bible/updates/14.html

It shows pretty much in english what the jist of xsl is. XSL isn't really anything more than an XML file anyways, so I don't think that it will be anymore impressive to show to a customer. There's also the main website for xsl which is:

http://www.w3.org/style/XSL/

XSLProcessor and Multiple Outputs?

Question

I recall seeing discussions about XSLProcessor producing more than one result from one XML and XSL. How can this can be achieved?

Answer

XML Parser 2.0.2.8 supports <ora:output> to handle this.

Good Books for XML/XSL

Question

Can any one suggest good books for learning about XML/XSL?

Answer

There are many excellent articles, whitepapers, and books that describe all facets of XML technology. Many of these are available on the world wide web. The following are some of the most useful resources we have found:

Version Number of XDK?

Question

How do I determine the version number of the XDK toolkit that I downloaded?

Answer

You can find out the full version number by looking at the readme.html file included in the archive and linked off of the Release Notes page.

Including Binary Data in an XML Document

Question

How do I include binary data in an XML document?

Answer

There is no way to directly include binary data within the document; however, there are two ways to work around this:

Converting XML to HTML

Question

How do I convert XML files into HTML files?

Answer

You need to create an XSL stylesheet to render your XML into HTML. You can start with an HTML document in your desired format and populated with dummy data. Then you can replace this data with the XSLT commands that will populate the HTML with data from the XML document completing your stylesheet.

XML Developer Kits for HP/UX Platform

Question

I would like to know if there are any release plans for the XML Parser or an XDK for HP/UX platform.

Answer

HP-UX ports for our C/C++ Parser as well as our C++ Class Generator are available. Look for an announcement on http://technet.oracle.com


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Solution Area

Contents

Index