This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Transformation Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Transformation Problem " Watch "Transformation Problem " New topic
Author

Transformation Problem

Sharang Thorat
Greenhorn

Joined: Dec 07, 2000
Posts: 21
Hello
i am using jsp to convert an xml to html by applying xsl sheet
this is sample code i am attaching

jsp code :
<%@ page language="java" contentType="text/html; charset=UTF-8"
import = "java.util.*,wt.httpgw.*,rs.jsp.bean.*,rs.desc.*,rs.jsp.util.*,org.apache.xalan.xslt.*,java.io.*,rs.jsp.helper.*,wt.util.WTMessage,wt.httpgw.EncodingConverter" %>
<jsp:useBean id="wtcontext" class="wt.httpgw.WTContextBean" scope="session"/>
<jsp:setProperty name="wtcontext" property="request" value="<%=request%>"/>
<%
File xmlfile = new File("C:\\RSD\\nwf\\newchildren.xml");
File stylesheet = new File("C:\\RSD\\nwf\\rsdstylesheet.xsl");

FileInputStream in = new FileInputStream(xmlfile);
FileInputStream xslfile = new FileInputStream(stylesheet);


XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
//StylesheetRoot parsedStyleSheet = null;

//parsedStyleSheet = processor.processStylesheet( new XSLTInputSource( xslfile ) );
//processor.setStylesheet(parsedStyleSheet);
try{
processor.process(new XSLTInputSource(in),null,new XSLTResultTarget(out));
}catch (Exception e)
{
System.out.println("******************************************");
e.printStackTrace();
}

%>
stylesheet :
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/rsData">
<html>
<head>
<title> Component Display </title>
</head>
<body>
<TABLE>
<xsl:apply-templates/>
</TABLE>
</body>
</html>
</xsl:template>

<xsl:template match="COMPONENT">
<TR>
<TD><xsl:value-of select="NAME" /></TD>
<TD><xsl:apply-templates/></TD>
</TR>
</xsl:template>

<xsl:template match="PORT" >
<TABLE>
<TR>
<TD><xsl:value-of select="name"/></TD>
</TR>
</TABLE>
</xsl:template>

</xsl:stylesheet>
and xml file to be parsed

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xml" href="rsdstylesheet.xsl"?>
<!DOCTYPE rsData SYSTEM "rsData_v2.dtd">
<rsData>
<HEADER dtdVersion="1.0"
creator="Administrator"
createdByApplication="PRO-CABLING"
owner="Administrator"
contents="DOCUMENT"
documentName="Assembly1"
systemName="COMPUTER"/>
<COMPONENT name="C" REFDES="C" context="NONE" type="COMPONENT">
<SYS_PARAMETER id="defID1"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portdefID1"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portdefID2"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portdefID3"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portdefID4"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<COMPONENT name="Panel" REFDES="Panel" context="NONE" type="COMPONENT">
<SYS_PARAMETER id="defID2"/>
<PARAMETER name="name" value="value"/>
</COMPONENT>
<COMPONENT name="Box" REFDES="Box" context="NONE" type="COMPONENT">
<SYS_PARAMETER id="defID3"/>
<PARAMETER name="name" value="value"/>
</COMPONENT>
<!-- Components inside of Panel definition -->
<COMPONENT name="Box1" REFDES="Box1" type="COMPONENT" context="NONE" >
<SYS_PARAMETER id="compID9"/>
<PARAMETER name="name" value="value"/>
</COMPONENT>
<COMPONENT name="Panel1" REFDES="Panel1" type="COMPONENT" context="COMPONENT" parentID="defID3" >
<SYS_PARAMETER id="compID5"/>
<PARAMETER name="name" value="value"/>
</COMPONENT>
<COMPONENT name="Panel2" REFDES="Panel2" type="COMPONENT" context="COMPONENT" parentID="compID9" >
<SYS_PARAMETER id="compID12"/>
<PARAMETER name="name" value="value"/>
</COMPONENT>
<COMPONENT name="C1" REFDES="C1" type="COMPONENT" context="COMPONENT" parentID="defID2" >
<SYS_PARAMETER id="compID1"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portID1"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portID2"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portID3"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portID4"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<COMPONENT name="C2" REFDES="C2" type="COMPONENT" context="COMPONENT" parentID="defID2" >
<SYS_PARAMETER id="compID2"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portID5"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portID6"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portID7"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portID8"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<!-- Components inside of box definition -->
<COMPONENT name="C1" REFDES="C1" type="COMPONENT" context="COMPONENT" parentID="compID5" >
<SYS_PARAMETER id="compID3"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portID9"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portID10"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portID11"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portID12"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<COMPONENT name="C2" REFDES="C2" type="COMPONENT" context="COMPONENT" parentID="compID5" >
<SYS_PARAMETER id="compID4"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portID13"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portID14"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portID15"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portID16"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<COMPONENT name="C1" REFDES="C1" type="COMPONENT" context="COMPONENT" parentID="compID8" >
<SYS_PARAMETER id="compID6"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portID17"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portID18"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portID19"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portID20"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<COMPONENT name="C2" REFDES="C2" type="COMPONENT" context="COMPONENT" parentID="compID8" >
<SYS_PARAMETER id="compID7"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portID21"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portID22"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portID23"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portID24"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<COMPONENT name="Panel1" REFDES="Panel1" type="COMPONENT" context="COMPONENT" parentID="defID3" >
<SYS_PARAMETER id="compID8"/>
<PARAMETER name="name" value="value"/>
</COMPONENT>
<!-- Components seen in diagram -->
<COMPONENT name="Panel1" REFDES="Panel1" type="COMPONENT" context="COMPONENT" parentID="compID9">
<SYS_PARAMETER id="compID10"/>
<PARAMETER name="name" value="value"/>
</COMPONENT>
<COMPONENT name="C2" REFDES="C2" type="COMPONENT" context="COMPONENT" parentID="compID10">
<SYS_PARAMETER id="compID11"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portID25"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portID26"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portID27"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portID28"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<COMPONENT name="C2" REFDES="C2" type="COMPONENT" context="COMPONENT" parentID="compID12">
<SYS_PARAMETER id="compID13"/>
<PARAMETER name="name" value="value"/>
<PORT name="1">
<SYS_PARAMETER id="portID29"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="2">
<SYS_PARAMETER id="portID30"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="3">
<SYS_PARAMETER id="portID31"/>
<PARAMETER name="name" value="value"/>
</PORT>
<PORT name="4">
<SYS_PARAMETER id="portID32"/>
<PARAMETER name="name" value="value"/>
</PORT>
</COMPONENT>
<!-- Wires inside of Panel definition -->
<!-- W1 inside of Panel-->
<CONNECTION name="W1" context="COMPONENT" parentID="defID2" type="SINGLE">
<SYS_PARAMETER id="connID1"/>
<PARAMETER name="name" value="value"/>
<NODE name="1" type="COMPONENT">
<SYS_PARAMETER id="nodeID1"/>
<ATTACH_TO compORconnID="compID1" nodeORportID="portID3"/>
</NODE>
<NODE name="2" type="COMPONENT">
<SYS_PARAMETER id="nodeID2"/>
<ATTACH_TO compORconnID="compID2" nodeORportID="portID7"/>
</NODE>
</CONNECTION>
<!-- W2 inside of Panel-->
<CONNECTION name="W2" context="COMPONENT" parentID="defID2" type="SINGLE">
<SYS_PARAMETER id="connID2"/>
<PARAMETER name="name" value="value"/>
<NODE name="1" type="COMPONENT">
<SYS_PARAMETER id="nodeID3"/>
<ATTACH_TO compORconnID="compID1" nodeORportID="portID4"/>
</NODE>
<NODE name="2" type="COMPONENT">
<SYS_PARAMETER id="nodeID4"/>
<ATTACH_TO compORconnID="compID2" nodeORportID="portID8"/>
</NODE>
</CONNECTION>
<!-- Wires inside of Box definition -->
<!-- W1 inside of Box-->
<CONNECTION name="W1" context="COMPONENT" parentID="defID3" type="SINGLE">
<SYS_PARAMETER id="connID3"/>
<PARAMETER name="name" value="value"/>
<NODE name="1" type="COMPONENT">
<SYS_PARAMETER id="nodeID5"/>
<ATTACH_TO compORconnID="compID3" nodeORportID="portID13"/>
</NODE>
<NODE name="2" type="COMPONENT">
<SYS_PARAMETER id="nodeID6"/>
<ATTACH_TO compORconnID="compID6" nodeORportID="portID17"/>
</NODE>
</CONNECTION>
<!-- W2 inside of Box-->
<CONNECTION name="W2" context="COMPONENT" parentID="defID3" type="SINGLE">
<SYS_PARAMETER id="connID4"/>
<PARAMETER name="name" value="value"/>
<NODE name="1" type="COMPONENT">
<SYS_PARAMETER id="nodeID7"/>
<ATTACH_TO compORconnID="compID3" nodeORportID="portID14"/>
</NODE>
<NODE name="2" type="COMPONENT">
<SYS_PARAMETER id="nodeID8"/>
<ATTACH_TO compORconnID="compID6" nodeORportID="portID18"/>
</NODE>
</CONNECTION>
<!-- Wires seen in diagram -->
<!-- W1 connected to Box1 Pannel1 C2-->
<CONNECTION name="W9" context="NONE" type="SINGLE">
<SYS_PARAMETER id="connID5"/>
<PARAMETER name="name" value="value"/>
<NODE name="1" type="COMPONENT">
<SYS_PARAMETER id="nodeID10"/>
<ATTACH_TO compORconnID="compID11" nodeORportID="portID25"/>
</NODE>
<!-- Other nodes -->
</CONNECTION>
<!-- W2 connected to Box1 Pannel1 C2-->
<CONNECTION name="W2" context="NONE" type="SINGLE">
<SYS_PARAMETER id="connID6"/>
<PARAMETER name="name" value="value"/>
<NODE name="1" type="COMPONENT">
<SYS_PARAMETER id="nodeID11"/>
<ATTACH_TO compORconnID="compID11" nodeORportID="portID26"/>
</NODE>
<!-- Other nodes -->
</CONNECTION>
<!-- W3 connected to Box1 Pannel2 C2-->
<CONNECTION name="W3" context="NONE" type="SINGLE">
<SYS_PARAMETER id="connID7"/>
<PARAMETER name="name" value="value"/>
<NODE name="1" type="COMPONENT">
<SYS_PARAMETER id="nodeID12"/>
<ATTACH_TO compORconnID="compID13" nodeORportID="portID29"/>
</NODE>
<!-- Other nodes -->
</CONNECTION>
<!-- W4 connected to Box1 Pannel2 C2-->
<CONNECTION name="W4" context="NONE" type="SINGLE">
<SYS_PARAMETER id="connID8"/>
<PARAMETER name="name" value="value"/>
<NODE name="1" type="COMPONENT">
<SYS_PARAMETER id="nodeID13"/>
<ATTACH_TO compORconnID="compID13" nodeORportID="portID30"/>
</NODE>
<!-- Other nodes -->
</CONNECTION>
</rsData>

Now the problem is when i do transfomratin on command line
what i get is just
html,body tag with title in it.
i also get all html tags for table but no attributes from xml.
when i use IE to fetch jsp the returned html is blank
if source of browser window is checked then its blank.
whats wrong in coding. xsl xml and its DTD are in same directory.
regards
sharang
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
Sharang, from your XML document it looks like your NAME value is
an attribute "name" of COMPONENT element (in low case letters) and
"name" attribute of PORT element. To get their value you should use
@name construct. So your templates will be
<xsl:template match="COMPONENT">
<TR>
<TD><xsl:value-of select="@name" /></TD>
<TD><xsl:apply-templates/></TD>
</TR>
</xsl:template>
<xsl:template match="PORT" >
<TABLE>
<TR>
<TD><xsl:value-of select="@name"/></TD>
</TR>
</TABLE>
</xsl:template>


Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Transformation Problem
 
Similar Threads
answer of this code
JNDI Port number issue while strating JBoss server 4.2.2.GA
[XSL] sort element
Get data by Matching ID's from two different XML documents
Replicate XML Node using XSL