XSL Result and its example
Posted on: January 19, 2011 at 12:00 AM
In this tutorial you will learn how to use XSLT result in struts2 for displaying data from JSP

XSL Result and its example

XSLT stands for XSL Transformations. It is the most important part of XSL. XSLT is a language which is used for transforming the XML document into other XML document or the language which browser recognize such as HTML, XHTML. With the XSLT you can rearrange or sort document, remove or add the attribute from the output file.

An Example of XSLT result is given below

index.jspADS_TO_REPLACE_1

<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
</head>
<body>
<s:form action="submit" method="Post">
<table>
<tr>
<td><s:textfield key="name" label="Specify Your Name "/></td>
</tr>

<tr>
<td><s:textfield key="address" label="Specify Your Address "/></td>
</tr>

<tr>
<td colspan="2"><s:submit value="OK"/></td>
</tr>
</table>
</s:form>
</body>
</html>

result.xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>
<xsl:template match="result">
<html>
<body>
<h2>XSLT Result Example</h2>

<h4>Name : <xsl:value-of select="name"/></h4>
<h4>Address :<xsl:value-of select="address"/></h4>

</body>
</html>
</xsl:template>

</xsl:stylesheet> 

XSLTResult.java

package net.roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class XSLTResult extends ActionSupport{
	
	private String name;
	private String address;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Override
	public String execute() throws Exception {
		String control=INPUT;
		// TODO Auto-generated method stub
		if((getName()!=null && getName().length()>0) && (getAddress()!=null && getAddress().length()>0)){
			control=SUCCESS;
		}
		return control;
	}
}

struts.xmlADS_TO_REPLACE_2

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<package name="xsltexample" namespace="/" extends="struts-default">

<action name="submit" class="net.roseindia.XSLTResult">
<result type="xslt" name="success">
<param name="stylesheetLocation">/jsp/result.xslt</param>
<param name="matchingPattern">^/result/[^/*]$</param>
</result>
<result name="input">/jsp/index.jsp</result>
</action>
</package>

</struts>

When you run this application it will display message as shown below:


 

Download this example code

Related Tags for XSL Result and its example:

Advertisements

Ads

Ads

 
Advertisement null

Ads