Hi,
I am facing a problem in transforming the XML to HTML. I suppose
the code is all right (as it works with a couple of other components)
but it does give the following exception when I am using the attached
XML file and XSL style sheet. I am using the following code,
tFactory = TransformerFactory.newInstance();
xmlStreamSource = new StreamSource(pipedIn);
// piepedIn is a PipedInputStream
xsltStreamSource = new StreamSource(stylesheet.toString());
//stylesheet is a URL to the XSL sheet
if(dtdurl != null)
xmlStreamSource.setSystemId(dtdurl.toString());
transformer = tFactory.newTransformer(xsltStreamSource);
result = new StreamResult(jspOut);
transformer.transform(xmlStreamSource, result);
The Exception is
Error while transforming.
javax.xml.transform.TransformerException: org.xml.sax.SAXParseException:
Document root element is missing. at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:686)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1088)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1066)
at
com.eneris.echainng.uicomponents.ThreadedUiComponentTag$ProcessorJob.execute(ThreadedUiComponentTag.java:351)
at
com.eneris.echainng.uicomponents.UiComponentJob.run(UiComponentJob.java:31)
at
com.eneris.util.ThreadPool$PooledThread.run(ThreadPool.java:834)
---------
org.xml.sax.SAXParseException: Document root element is missing.
at org.apache.cr!
imson.parser.Parser2.fatal(Parser2.java:3108)
at
org.apache.crimson.parser.Parser2.fatal(Parser2.java:3096)
at
org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:501)
at
org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:433)
at
org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:349)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:630)
at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1088)
at org.apache.xalan.transform!
er.TransformerImpl.transform(TransformerImpl.java:1066)
at
com.eneris.echainng.uicomponents.ThreadedUiComponentTag$ProcessorJob.execute(ThreadedUiComponentTag.java:351)
at
com.eneris.echainng.uicomponents.UiComponentJob.run(UiComponentJob.java:31)
at
com.eneris.util.ThreadPool$PooledThread.run(ThreadPool.java:834)
I'll really thankful if some one gets me out of this.
BR,
Faisal.
--
Faisal Mahmood
Eneris Solutions Oy 7 Torikatu,90100,Oulu.
Email: [EMAIL PROTECTED] GSM:0503845573
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:variable name="dbid" select="//DataBrowser/@id"/>
<xsl:variable name="form.method" select="//FormInfo/@method"/>
<xsl:variable name="form.action" select="//FormInfo/@action"/>
<xsl:variable name="i18n.page" select="//[EMAIL PROTECTED]'page']"/>
<xsl:variable name="i18n.page.next" select="//[EMAIL PROTECTED]'page.next']"/>
<xsl:variable name="i18n.page.prev" select="//[EMAIL PROTECTED]'page.prev']"/>
<xsl:variable name="i18n.sort.ascending" select="//[EMAIL
PROTECTED]'sort.ascending']"/>
<xsl:variable name="i18n.sort.descending" select="//[EMAIL
PROTECTED]'sort.descending']"/>
<xsl:variable name="icon.null" select="'pics/databrowser2-icon-null.png'"/>
<xsl:variable name="icon.sort" select="'pics/databrowser2-icon-sort.png'"/>
<xsl:variable name="icon.sort.ascending"
select="'pics/databrowser2-icon-sort-ascending.png'"/>
<xsl:variable name="icon.sort.descending"
select="'pics/databrowser2-icon-sort-descending.png'"/>
<xsl:variable name="icon.width" select="'12'"/>
<xsl:variable name="icon.height" select="'12'"/>
<xsl:template match="/">
<form name="{$dbid}" method="{$form.method}" action="{$form.action}"
class="databrowser2">
<table width="100%" border="0" class="databrowser2">
<tr>
<td width="50%">
<xsl:apply-templates select="//Title" />
</td>
<td width="50%">
<xsl:apply-templates select="//PageInfo">
<xsl:with-param name="cu" select="1"/>
</xsl:apply-templates>
</td>
</tr>
<tr>
<td width="100%" colspan="2">
<table width="100%" border="0" cellspacing="2" cellpadding="2"
class="databrowser2">
<xsl:apply-templates select="//CellHeaders"/>
<xsl:apply-templates select="//Body" />
<xsl:apply-templates select="//Message" />
</table>
</td>
</tr>
<tr>
<td width="100%" colspan="2">
<xsl:apply-templates select="//FormInfo"/>
</td>
</tr>
</table>
</form>
</xsl:template>
<xsl:template match="Title">
<h3 class="databrowser2-title">
<xsl:apply-templates/>
</h3>
</xsl:template>
<xsl:template match="Body">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Row">
<xsl:variable name="pos" select="position() div 2"/>
<xsl:variable name="row_parity">
<xsl:choose>
<xsl:when test="(2*round($pos div 2)) = $pos">even</xsl:when>
<xsl:otherwise>odd</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr>
<xsl:apply-templates>
<xsl:with-param name="row_id" select="@id"/>
<xsl:with-param name="row_parity" select="$row_parity"/>
</xsl:apply-templates>
</tr>
</xsl:template>
<xsl:template match="Cell">
<xsl:param name="row_id"/>
<xsl:param name="row_parity"/>
<td style="[EMAIL PROTECTED]" class="databrowser2-row-$row_parity">
<xsl:apply-templates>
<xsl:with-param name="cell_id" select="@id"/>
<xsl:with-param name="row_id" select="$row_id"/>
<xsl:with-param name="row_parity" select="$row_parity"/>
</xsl:apply-templates>
</td>
</xsl:template>
<xsl:template match="CellHeaders">
<tr>
<xsl:apply-templates>
<xsl:with-param name="linkprefix" select="@linkprefix"/>
</xsl:apply-templates>
</tr>
</xsl:template>
<xsl:template match="CellHeader">
<xsl:param name="linkprefix"/>
<th width="[EMAIL PROTECTED]" class="databrowser2-row-header">
<xsl:choose>
<xsl:when test="@sortable = 'ascending'">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="99%" align="left">
<a href="[EMAIL PROTECTED]&{$dbid}_sortmethod=descending"
class="databrowser2-row-header">
<xsl:value-of select="@title"/>
</a>
</td>
<td width="1%" align="right">
<a href="[EMAIL PROTECTED]&{$dbid}_sortmethod=descending"
class="databrowser2-row-header">
<img src="{$icon.sort.ascending}" width="{$icon.width}"
height="{$icon.height}" border="0" align="middle" alt="{$i18n.sort.descending}"
/>
</a>
</td>
</tr>
</table>
</xsl:when>
<xsl:when test="@sortable = 'descending'">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="99%" align="left">
<a href="[EMAIL PROTECTED]&{$dbid}_sortmethod=ascending"
class="databrowser2-row-header">
<xsl:value-of select="@title"/>
</a>
</td>
<td width="1%" align="right">
<a href="[EMAIL PROTECTED]&{$dbid}_sortmethod=ascending"
class="databrowser2-row-header">
<img src="{$icon.sort.descending}" width="{$icon.width}"
height="{$icon.height}" border="0" align="middle" alt="{$i18n.sort.ascending}"
/>
</a>
</td>
</tr>
</table>
</xsl:when>
<xsl:when test="@sortable = 'true'">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="99%" align="left">
<a href="[EMAIL PROTECTED]&{$dbid}_sortmethod=ascending"
class="databrowser2-row-header">
<xsl:value-of select="@title"/>
</a>
</td>
<td width="1%" align="right">
<a href="[EMAIL PROTECTED]&{$dbid}_sortmethod=ascending"
class="databrowser2-row-header">
<img src="{$icon.sort}" width="{$icon.width}"
height="{$icon.height}" border="0" align="middle" alt="{$i18n.sort.ascending}"
/>
</a>
</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@title"/>
</xsl:otherwise>
</xsl:choose>
</th>
</xsl:template>
<xsl:template match="Message">
<xsl:variable name="cols" select="count(//CellHeader)"/>
<tr>
<td width="100%" colspan="{$cols}">  
<xsl:apply-templates/>
</td>
</tr>
</xsl:template>
<xsl:template match="f">
<span style="[EMAIL PROTECTED]">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="l">
<a href="[EMAIL PROTECTED]" title="[EMAIL PROTECTED]">
<xsl:apply-templates/>
</a>
</xsl:template>
<xsl:template match="Object">
<xsl:param name="cell_id"/>
<xsl:param name="row_id"/>
<xsl:choose>
<xsl:when test="@type = 'textfield'">
<xsl:variable name="size">
<xsl:choose>
<xsl:when test="@size">
<xsl:value-of select="@size"/>
</xsl:when>
<xsl:otherwise>20</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="maxlength">
<xsl:choose>
<xsl:when test="@maxsize">
<xsl:value-of select="@maxsize"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$size"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<input type="text" name="[EMAIL PROTECTED]" size="{$size}"
maxlength="{$maxlength}" value="[EMAIL PROTECTED]"/>
</xsl:when>
<xsl:when test="@type = 'rowselect'">
<xsl:choose>
<xsl:when test="@multiple = 'true'">
<xsl:choose>
<xsl:when test="@selected = 'true'">
<input type="checkbox" name="selection{$row_id}" value="selected"
checked="true"/>
</xsl:when>
<xsl:otherwise>
<input type="checkbox" name="selection{$row_id}" value="selected"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="@multiselection = 'true'">
<xsl:choose>
<xsl:when test="@selected = 'true'">
<input type="checkbox" name="multiselection" value="{$row_id}"
checked="true"/>
</xsl:when>
<xsl:otherwise>
<input type="checkbox" name="multiselection" value="{$row_id}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="@selected = 'true'">
<input type="radio" name="selection" value="{$row_id}"
checked="true"/>
</xsl:when>
<xsl:otherwise>
<input type="radio" name="selection" value="{$row_id}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="@type = 'radio'">
<xsl:variable name="name">
<xsl:choose>
<xsl:when test="@name"><xsl:value-of select="@name"/></xsl:when>
<xsl:otherwise>radio_<xsl:value-of select="$cell_id"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="@selected = 'true'">
<input type="radio" name="{$name}" value="[EMAIL PROTECTED]"
checked="true" />
</xsl:when>
<xsl:otherwise>
<input type="radio" name="{$name}" value="[EMAIL PROTECTED]" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="@type = 'listseparator'">
<xsl:choose>
<xsl:when test="@itemtype= 'true'">
 
</xsl:when>
<xsl:otherwise>
•
</xsl:otherwise>
</xsl:choose>
<input type="hidden" name="[EMAIL PROTECTED]" value="[EMAIL PROTECTED]" />
</xsl:when>
<xsl:otherwise>
<i>[Object :<xsl:value-of select="@type"/>]</i>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="PageInfo">
<p class="databrowser2-pager">
<xsl:value-of select="$i18n.page"/>
 
<b><xsl:value-of select="@current"/></b>
/
<b><xsl:value-of select="@total"/></b>
 
<xsl:choose>
<xsl:when test="@current = 1">
<xsl:value-of select="$i18n.page.prev"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="target" select="@current - 1"/>
<a href="[EMAIL PROTECTED]">
<xsl:value-of select="$i18n.page.prev"/>
</a>
</xsl:otherwise>
</xsl:choose>
 
<xsl:choose>
<xsl:when test="@current = @total">
<xsl:value-of select="$i18n.page.next"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="target" select="@current + 1"/>
<a href="[EMAIL PROTECTED]">
<xsl:value-of select="$i18n.page.next"/>
</a>
</xsl:otherwise>
</xsl:choose>
 
<xsl:apply-templates>
<xsl:with-param name="current" select="@current"/>
<xsl:with-param name="linkprefix" select="@linkprefix"/>
</xsl:apply-templates>
</p>
</xsl:template>
<xsl:template match="ListPage">
<xsl:param name="current"/>
<xsl:param name="linkprefix"/>
<xsl:param name="dbid"/>
<xsl:choose>
<xsl:when test="@value = $current">
<b><xsl:value-of select="@value"/></b>
</xsl:when>
<xsl:otherwise>
<a href="[EMAIL PROTECTED]">
<xsl:value-of select="@value"/>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="I18n">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="FormInfo">
<table width="100%" border="0" cellspacing="2" cellpadding="2"
class="databrowser2">
<xsl:apply-templates select="//Text"/>
<xsl:apply-templates select="//Textfield"/>
</table>
<table width="100%" border="0" cellspacing="2" cellpadding="2"
class="databrowser2">
<tr>
<td width="50%">
<xsl:apply-templates select="//HiddenValue"/>
<xsl:apply-templates select="//SubmitButton"/>
<xsl:apply-templates select="//ResetButton"/>
</td>
<td width="50%">
<!-- sivuttaja -->
<xsl:apply-templates select="//PageInfo">
<xsl:with-param name="cu" select="1" />
</xsl:apply-templates>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="HiddenValue">
<input type="hidden" name="[EMAIL PROTECTED]" value="[EMAIL PROTECTED]"/>
</xsl:template>
<xsl:template match="SubmitButton">
<xsl:choose>
<xsl:when test="@id">
<input type="submit" name="[EMAIL PROTECTED]" value="[EMAIL PROTECTED]"
class="databrowser2"/>
</xsl:when>
<xsl:otherwise>
<input type="submit" name="submit" value="[EMAIL PROTECTED]"
class="databrowser2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="ResetButton">
<input type="reset" name="reset" value="[EMAIL PROTECTED]"
class="databrowser2"/>
</xsl:template>
<xsl:template match="Text">
<tr>
<xsl:choose>
<xsl:when test="@title">
<xsl:variable name="cell.width"
select="round(100-floor(number(translate(@width,'%',''))))" />
<td class="databrowser2-title2" align="right" width="{$cell.width}%">
<xsl:value-of select="@title"/>
</td>
<td class="databrowser2-under-row" width="[EMAIL PROTECTED]" align="left">
<xsl:value-of select="@value"/>
</td>
</xsl:when>
<xsl:otherwise>
<td class="databrowser2-under-row" width="100%" colspan="2">
<xsl:value-of select="@value"/>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:template>
<xsl:template match="Textfield">
<tr>
<xsl:variable name="size">
<xsl:choose>
<xsl:when test="@size">
<xsl:value-of select="@size"/>
</xsl:when>
<xsl:otherwise>20</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="maxlength">
<xsl:choose>
<xsl:when test="@maxsize">
<xsl:value-of select="@maxsize"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$size"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="@title">
<xsl:variable name="cell.width"
select="round(100-floor(number(translate(@width,'%',''))))" />
<td class="databrowser2-title2" align="right" width="{$cell.width}%">
<xsl:value-of select="@title"/>
</td>
<td class="databrowser2-under-row" width="[EMAIL PROTECTED]" align="left">
<input type="text" name="[EMAIL PROTECTED]" size="{$size}"
maxlength="{$maxlength}" value="[EMAIL PROTECTED]"/>
</td>
</xsl:when>
<xsl:otherwise>
<td class="databrowser2-under-row" width="100%" colspan="2">
<input type="text" name="[EMAIL PROTECTED]" size="{$size}"
maxlength="{$maxlength}" value="[EMAIL PROTECTED]"/>
</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:template>
</xsl:stylesheet>
<!-- DTD for DataBrowser2 output -->
<!-- entityt - perus -->
<!ENTITY % boolean "(true|false)" >
<!ENTITY % bodycontent "#PCDATA | f | l" >
<!ENTITY % objects "rowselect|radio|textfield|listseparator" >
<!ENTITY % Bodycontent "( %bodycontent; )*" >
<!-- entityt - parametriryhm�t -->
<!ENTITY % style "style CDATA #IMPLIED" >
<!ENTITY % object.params '
name CDATA #IMPLIED
value CDATA #IMPLIED
width CDATA #IMPLIED
height CDATA #IMPLIED
size CDATA #IMPLIED
maxsize CDATA #IMPLIED
itemtype CDATA #IMPLIED
selected %boolean; "false"
multiple %boolean; "false"
multiselection %boolean; "false"
alt CDATA #IMPLIED
'>
<!-- top-level tags -->
<!ELEMENT EChainNG-DataBrowser2 (Meta,(Body|Message))>
<!ELEMENT Meta (DataBrowser, Title, CellHeaders, I18n, PageInfo?, FormInfo?)>
<!ELEMENT Body (Row)*>
<!-- Meta -->
<!ELEMENT DataBrowser EMPTY>
<!ATTLIST DataBrowser
id CDATA #REQUIRED
>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT CellHeaders (CellHeader)*>
<!ATTLIST CellHeaders
linkprefix CDATA #IMPLIED
>
<!ELEMENT I18n (I18nTag)*>
<!ELEMENT PageInfo (ListPage*)>
<!ATTLIST PageInfo
current CDATA #REQUIRED
total CDATA #REQUIRED
linkprefix CDATA #IMPLIED
>
<!ELEMENT ListPage EMPTY>
<!ATTLIST ListPage
value CDATA #REQUIRED
>
<!ELEMENT FormInfo (HiddenValue*,Text*,Textfield*,SubmitButton+,ResetButton?)>
<!ATTLIST FormInfo
action CDATA #REQUIRED
method (post|get) #REQUIRED
>
<!ELEMENT CellHeader EMPTY>
<!ATTLIST CellHeader
title CDATA #REQUIRED
id CDATA #REQUIRED
width CDATA #IMPLIED
sortable (ascending|descending|true|false) "true"
>
<!ELEMENT I18nTag (#PCDATA)>
<!ATTLIST I18nTag
key CDATA #REQUIRED
>
<!ELEMENT HiddenValue EMPTY>
<!ATTLIST HiddenValue
key CDATA #REQUIRED
value CDATA #REQUIRED
>
<!ELEMENT SubmitButton EMPTY>
<!ATTLIST SubmitButton
id CDATA #IMPLIED
title CDATA #REQUIRED
>
<!ELEMENT ResetButton EMPTY>
<!ATTLIST ResetButton
title CDATA #REQUIRED
>
<!ELEMENT Text EMPTY>
<!ATTLIST Text
title CDATA #IMPLIED
value CDATA #REQUIRED
width CDATA #REQUIRED
>
<!ELEMENT Textfield EMPTY>
<!ATTLIST Textfield
title CDATA #IMPLIED
value CDATA #REQUIRED
size CDATA #REQUIRED
maxsize CDATA #IMPLIED
width CDATA #REQUIRED
name CDATA #IMPLIED
>
<!-- Body -->
<!ELEMENT f %Bodycontent; >
<!ATTLIST f
%style;
>
<!ELEMENT l (#PCDATA)>
<!ATTLIST l
href CDATA #REQUIRED
title CDATA #IMPLIED
%style;
>
<!-- <!ELEMENT Cell (#PCDATA|f|l|Object)*> -->
<!ELEMENT Cell (%bodycontent;|Object)*>
<!ATTLIST Cell
id CDATA #REQUIRED
%style;
>
<!ELEMENT Row (Cell*)>
<!ATTLIST Row
id CDATA #REQUIRED
>
<!ELEMENT Object EMPTY>
<!ATTLIST Object
type (%objects;) #REQUIRED
%object.params;
%style;
>
<!ELEMENT Message %Bodycontent; >
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE EChainNG-DataBrowser2 PUBLIC "-//Eneris//DTD DataBrowser2 output//EN" "file:/home/faisal/nemo/dtd/EChainNG-DataBrowser2.dtd">
<EChainNG-DataBrowser2>
<Meta>
<DataBrowser id="companybrowser"/>
<Title/>
<CellHeaders linkprefix="/nemo/management.jsp?">
<CellHeader width="1%" title="V" sortable="false" id="COMPANYID"/>
Companies
</CellHeaders>
<I18n>
<I18nTag key="page.next">
Page</I18nTag>
</I18n>
<PageInfo total="21" current="1" linkprefix="/nemo/management.jsp?companybrowser_sortby=NAME&companybrowser_sortmethod=ascending&">
<ListPage value="1"/>
<ListPage value="2"/>
</PageInfo>
<FormInfo action="servlet/CompanyManagementServlet" method="post">
<HiddenValue key="action" value="ask"/>
<SubmitButton title="Edit" id="edit"/>
<SubmitButton title="New" id="new"/>
<ListPage value="20"/>
<SubmitButton title="Delete" id="delete"/>
</FormInfo>
</Meta>
<Body>
<Row id="623">
</Row>
</Body>
</EChainNG-DataBrowser2>