XML
XML
XSLT is far more sophisticated than CSS. With XSLT you can add/remove elements and
attributes to or from the output file. You can also rearrange and sort elements,
perform tests and make decisions about which elements to hide and display, and a
lot more.
XSLT Example
We will use the following XML document:
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple
syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped
cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and
whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash
browns</description>
<calories>950</calories>
</food>
</breakfast_menu>
Use XSLT to transform XML into HTML, before it is displayed in a browser:
///rmi
WHAT WE DO
CORPORATE
EXPLORE
STORE
BLOG
CONTACT
SIGN UP
LOG IN
Library
AIM:
PROCEDURE:
Client file .
PROGRAM:
CLIENT PROGRAM:
import java.io.*;
import java.rmi.*;
try
String s="rmi://"+args[0]+"/abc";
serverint f=(serverint)Naming.lookup(s);
int n1=Integer.parseInt(m.readLine());
catch(Exception e)
System.out.println(e);
}
INTERFACE PROGRAM:
import java.rmi.*;
IMPLEMENTATION PROGRAM:
import java.rmi.*;
import java.rmi.server.*;
int i,c=1;
for(i=1;i<=n;i++)
c=i*c;
return c;
}
SERVER PROGRAM:
import java.net.*;
import java.rmi.*;
try
Naming.rebind("abc",m);
catch(Exception e)
System.out.println("Exception"+e);
OUTPUT:
SERVER WINDOW:
C:\vino20>javac serverint.java
C:\vino20>javac serverimpl.java
C:\vino20>javac server.java
C:\vino20>rmic serverimpl
C:\vino20>start rmiregistry
C:\vino20>java server
CLIENT WINDOW:
C:\vino20>javac client.java
the factorial is 6
C:\vino20>
English,RMI IN JAVA
Average Rating:
0 ratings
Share
0
inShare
0
kannan
Sun, 10/11/2009 - 18:42
life is short so make it sweet
Comments (0)
Sign Up
or Login
ABOUT
Our Mission
Why Classle?
Corporate
Features
Services
MEDIA
Media Releases
Case Studies
Press
CONTACT
Contact Us
Careers
HELP
FAQ
Report a Problem
SOCIAL
Facebook
Twitter
LinkedIn
Google+
Blog
import java.rmi.*;
AddServerImpl.java
import java.rmi.*;
import java.rmi.server.*;
AddServer.java
import java.net.*;
import java.rmi.*;
AddClient.java
import java.rmi.*;
<html>
<body>
<h1>Welcome</h1>
Mr. John Smith<br>
</body>
</html>
Opening the XML document using Internet Explorer 5.x or later results in the
following display:
Looking at LIST2, you can see that the HTML tags and XSLT commands are both used.
In order to decipher what parts of the code are XSLT commands, we designate the
following namespace:
http://www.w3.org/1999/XSL/Transform
This description indicates an XSLT command. Designating this for all XSLT commands
creates redundancy, so we associate the description with a prefix. Any prefix can
be used, but the prefix "xsl" is used most frequently with XSLT. The prefix and the
element name are separated by a colon (:). In other words, "xsl:�" is notated to
separate transformation commands and output data. Since the XSLT stylesheet is an
XML document, a root element is required. The root element of an XSLT stylesheet is
"xsl:stylesheet element."
The various commands for document transformation are described in the child
element(s) of the xsl:stylesheet element. The element described directly below the
xsl:stylesheet element is called the "top level element." The following are
elements that can be coded as a top level element:
attribute-set
key
param
template
decimal-format
namespace-alias
preserve-space
variable
include
output
strip-space
Specific transformation content is called "Templates" (lines 5 through 10 in
LIST2); templates are described in "Template Rules." The "xsl:template element" is
what represents the template rules (lines 4 through 11 in LIST2).
Because it is not an XML document, an HTML document can be coded in different ways
that would not be accepted as a well-formed XML document (attributes not surrounded
by quotes; open tag with no closing tag, etc.). However, an XSLT stylesheet is an
XML document, and as such, must be a well-formed document. Accordingly, the HTML br
element <br> must always be notated as an empty element (<br/>) (line 8 in LIST2).
With XPath, the component elements of an XML document are treated as nodes. For
example, following Figure represents the result of expressing the XML document
LIST4 via XPath in nodes.
To designate a node, nodes are separated by the "/" character in order from the
root node down through each hierarchy level. For example, taking the ProductName
element from LIST4, the XPath method would be "/Catalog/Product/ProductName". Under
XSLT, the node to be processed with respect to the template rule is designated.
This is the match attribute (line 4 of LIST5) of the xsl:template element.
If the current node in LIST4 is the Catalog element node, then the XPath notation
for the ProductName element would be "Product/ProductName".
On line 8 of LIST2, the "John Smith" (from the designated "UserList/User/Name" text
content) is extracted, and then output as the transformation result.
The XSLT processor first applies the template rule that processes the root node,
executing the template within the applied template rules in order from top to
bottom.
Review Questions
Question 1
Select which of the following is incorrect as a method for using XSLT.
Question 2
Select which of the following is correct as an XSLT stylesheet notation.
<template match="/">
<html>
<body>
<h1>Welcome</h1>
Hello<value-of select="UserList/User/Name" /> <br/>
</body>
</html>
</template>
</stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<html>
<body>
<h1>Welcome</h1>
Hello<xsl:value-of select="UserList/User/Name" /><br/>
</body>
</html>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Welcome</h1>
Hello<xsl:value-of select="UserList/User/Name" /><br>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Welcome</h1>
Hello<xsl:value-of select="UserList/User/Name" /><br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Comments
With XSLT stylesheets, the namespace "http://www.w3.org/1999/XSL/Transform" must be
declared using the element associated with the namespace. If the namespace is not
designated, the XSLT command will not be recognized, even if it is the same element
name as the XSLT. The template is described as the child element of the
xsl:template element, but it cannot be written directly beneath the xsl:stylesheet
element. In addition, since the XSLT stylesheet is an XML document, it must be a
well-formed document.
The HTML <br> tag must be written as <br/>. Accordingly, the correct answer is D.
Question 3
Select which of the following is the correct XPath notation corresponding to (1),
when you want to transform the following XML document into HTML using an XSLT
stylesheet. Select all that apply.
[XML Document]
<?xml version="1.0" encoding="UTF-8"?>
<Snack>
<Yesterday>
<Fruit>Banana</Fruit>
</Yesterday>
<Today>
<Fruit>Watermelon</Fruit>
</Today>
<Tomorrow>
<Fruit>Melon</Fruit>
</Tomorrow>
</Snack>
[XSL Stylesheet]
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Snack</h1>
<xsl:apply-templates select="Snack/Tomorrow"/>
</body>
</html>
</xsl:template>
<xsl:template match="Tomorrow">
Snack will be<xsl:value-of select=" (1) " /><br/>
</xsl:template>
</xsl:stylesheet>
[HTML Document]
<html>
<body>
<h1>Snack</h1>
Snack will be Melon<br>
</body>
</html>
/Snack/Tomorrow/Fruit
Snack/Tomorrow/Fruit
Tomorrow/Fruit
Fruit
Comments
With XPath, the absolute path is written beginning with the "/" character, while a
path not beginning with the "/" character is a relative path. In this question, the
fruit element node below the Tomorrow element node is designated. Expressing the
absolute path results in "/Snack/Tomorrow/Fruit", and in the case of a relative
path, the node designated in the match attribute of the xsl:template element is the
current node. Here, the current node is the Tomorrow element node, so expressing
the relative path results in "Fruit". Accordingly, the correct answers are A and D.
Tomoya Suzuki
Toshiba OA Consultant, Ltd. Training Solutions Engineering Department. Mr. Suzuki
works mainly as an instructor in XML and programming language seminars. He laments
that, for some reason, all of the rainy days during rainy season were on the
weekends this year, preventing him from playing tennis, and causing him to suffer
from a lack of exercise. He does predict, however, that he will have a deep, dark
tan by the time this article is published. Don't forget the sun block, Tomoya.
best RMI
RMI application for counting factorial of a given number.
Code for RMI application for counting factorial of a given number. in Java
// FactRMI.java Interfacepublicinterface FactRMI extends java.rmi.Remote
{
long countfact(int num) throws java.rmi.RemoteException;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
// FactRMIServer.java
import java.rmi.*;
import java.rmi.server.*;
publicclass FactRMIServer
{
try
{
// Create CountRMIImpl
FactRMIImpl myFact = new FactRMIImpl("//Binita/myFactRMI");
System.out.println("FactRMI Server ready.");
}
catch (Exception e)
{
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}
}
}
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.io.DataInputStream;
publicclass FactRMIClient
{ publicstaticvoid main(String args[])
{
// Create and install the security manager
System.setSecurityManager(new RMISecurityManager());
DataInputStream in = new DataInputStream(System.in);
int num;
try
{
FactRMI myFact = (FactRMI)Naming.lookup("//"
+ args[0] + "/" + "myFactRMI");
// OUTPUT
CLIENT PROGRAM:
import java.io.*;
import java.rmi.*;
try
String s="rmi://"+args[0]+"/abc";
serverint f=(serverint)Naming.lookup(s);
int n1=Integer.parseInt(m.readLine());
catch(Exception e)
System.out.println(e);
INTERFACE PROGRAM:
import java.rmi.*;
public interface serverint extends Remote
IMPLEMENTATION PROGRAM:
import java.rmi.*;
import java.rmi.server.*;
int i,c=1;
for(i=1;i<=n;i++)
c=i*c;
return c;
SERVER PROGRAM:
import java.net.*;
import java.rmi.*;
try
Naming.rebind("abc",m);
catch(Exception e)
System.out.println("Exception"+e);
OUTPUT:
SERVER WINDOW:
C:\>javac serverint.java
C:\>javac serverimpl.java
C:\>javac server.java
C:\>rmic serverimpl
C:\>start rmiregistry
C:\>java server
CLIENT WINDOW:
C:\>javac client.java
the factorial is 6
SHARE
SHARE
Comments
<body class="body">
<header class="mainheader"/>
<img src="img/logo.png" alt="logo"/>
<nav>
<ul>
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Portfoliow</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<div class="maincontent">
<div class="content">
<article class="t�
SHARE
POST A COMMENT
READ MORE
simple question with answers
August 15, 2013
Five friends have their gardens next to one another, where they grow three kinds of
crops: fruits (apple, pear, nut, cherry), vegetables (carrot, parsley, gourd,
onion) and flowers (aster, rose, tulip, lily).
1. They grow 12 different varieties.