Home | | Web Technology | XSL

Chapter: Web Technology : Representing Web Data

XSL

XSL is stands for eXtensible Style sheet Language which is an xml vocabulary.

XSL

 

XSL is stands for eXtensible Style sheet Language which is an xml vocabulary. It contains two

 

Types of information:Template data: Which is text that is copied to output xml document with change or no change.

 

XSL markup: which controls transformation process. It uses two namespaces:

 

o http://www.w3.org/1999/xsl/Transform is the namespace name for xsl namespace

 

o http://www.w3.org/1999/xhtml is the xhtml namesapce name

 

1. XSL components:

Three components

1. XSLT

2. XPATH

3. XSL-FO

 

XSLT – XSL Transformations (XSLT) is a language to specify transformations of XML documents. A transformation expressed in XSLT describes rules for transforming a source tree into a result tree

 

XPATH- is used to find information in an XML document. It navigates through elements and attributes in XML documents.

 

XSL-FO is a XSL Formatter an xml vocabulary for defining style properties of xml document.

 

To transform xml document the following things are required:

 

a. Source xml document

 

b.   Xslt style sheet that defines the information of source xml program to be transformed

 

c. Xslt processor that performs transformation

 

The following program illustrates that.

 

The JAXP is a tool which is used as XSLT processor. The XSLT processor receives xslt and xml program as its input and generates another xml program as its output where we can see the content retrieved from source xml program.

 

Example for XSLT

 

Step 1. Create an XML file and save as myXML.xml The code for the emp.xml file is given below:

 

<?xml version = "1.0" ? > <Employee-Detail> <Employee>

 

<Emp_Id> E-001 </Emp_Id> <Emp_Name> Nisha </Emp_Name>

 

<Emp_E-mail> Nisha1@yahoo.com </Emp_E-mail> </Employee>

 

<Employee>

 

<Emp_Id> E-002 </Emp_Id> <Emp_Name> Amit</Emp_Name>

 

<Emp_E-mail> Amit2@yahoo.com </Emp_E-mail> </Employee>

 

</Employee-Detail>

 

Step 2: Create an XSLT Stylesheet and save as myXSL.xsl extension <?xml version="1.0" ?>

 

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/">

 

<html><head><title> XSL for Transforamtion </title> <body><p>

 

<xsl:for-each select="Employee"> <xsl:value-of select="child::Emp_Id"/> <xsl:value-of select="child::Emp_Name"/> <xsl:value-of select="child::Emp_E-mail"/> </xsl:for-each>

 

</p></body></html>

</xsl:template>

</xsl:stylesheet>

 

Step 3: Create XML Transformer program in java and give input both .xml and .xsl file import javax.xml.transform.Transformer;

 

import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.Source;

 

import javax.xml.transform.Result; import javax.xml.transform.OutputKeys; public class XMLwithXSLT

{

 

public static void main(String[] args) throws Exception

{

 

Source source = new StreamSource("myXML.xml"); Source xsl = new StreamSource("myXSL.xsl");

TransformerFactory factory = TransformerFactory.newInstance();

 

 

 

Transformer transformer = factory.newTransformer(xsl); new StreamResult(System.out);

}

}

 

 

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Web Technology : Representing Web Data : XSL |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.