How to Import a XSL File inside a XML File

This tip describes, how you can use a XSL(extensible StyleSheet file) inside a XML file to generate a HTML format of that file thus making it more user-friendly.

Let’s Convert this XML File to a Html Format Using XSL StyleSheet:






HindolaRoad
Dhenkanal
BBSR
OR
12345
IN/country>


Miss
Monalisha
Nayak






Polasara
Berhampur
BBSR
OR
12345
IN/country>


Miss
Surama
Hotta



 
To apply stylesheet inside a xml file added following code in the xml file

 
fileName.xml is the name of the stylesheet file you want to import.

To select the rootNode from the XML tree in a stylesheet we create a Pattern to select the root node, the Pattern is given below:

the match = “/” defines the the template with the root of the XML source document.

A template contains rules to apply when a specified node is matched.

Ex: 

it checks whether the xml file contain a node named ‘StudentInfo’ or not.

To Extract the Value of a Selected Node: use

ex:

 
To get the attribute value of a node:

 
The elements applies a template to the current elements or to the current elements chile nodes.

To Declare a Variable inside a Xsl File:

 
To give Comment inside a xml file:

hello this is the Comment

 
To Declare a Method inside a xml File:

 // GetName is the Name of the method

 
Method Defination:(It first check whether the prefix, firstname,lastname is present or not. if present then dispaly).







  // this line add a space after prefix.

 

 





 
Xsl-If:

This element is used to put a conditional text against the content of the XML file.

Ex: If we check whether the Student id is present or not then. we use this code:

Student Id: 

 
Xsl:Choose:

The elements is used with and to check multiple conditions.

Ex: this example is given inside the GetName method.

Xsl:for-each:

the elements used for looping inside a XSLT file.



 // . means it select all the complete address for the student including streetaddressline, city, stste, postalcode etc with in a single line.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!