Friday 31 August 2012

XSLT


XSLT stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents.

XSLT also stands for XSL Transformations. In this tutorial you will learn how to use XSLT to transform XML documents into other formats, like XHTML.

XSLT Functions

Functions are often called with the fn: prefix, such as fn:string(). However, since fn: is the default prefix of the namespace, the function names do not need to be prefixed when called.

In addition, there are the following built-in XSLT functions:

Name
Description
current()
Returns the current node
document()
Used to access the nodes in an external XML document
element-available()
Tests whether the element specified is supported by the XSLT processor
format-number()
Converts a number into a string
function-available()
Tests whether the function specified is supported by the XSLT processor
generate-id()
Returns a string value that uniquely identifies a specified node
key()
Returns a node-set using the index specified by an <xsl:key> element
system-property()
Returns the value of the system properties
unparsed-entity-uri()
Returns the URI of an unparsed entity


current() Function

Usage of Current() : The current() function returns a node-set that contains only the current node. Usually the current node and the context node are the same.

<xsl:value-of select="current()"/>
is equal to
<xsl:value-of select="."/>
However, there is one difference. Look at the following XPath expression: "catalog/cd". This expression selects the <catalog> child nodes of the current node, and then it selects the <cd> child nodes of the <catalog> nodes. This means that on each step of evaluation, the "." has a different meaning.
The following line:
<xsl:apply-templates select="//cd[@title=current()/@ref]"/>
will process all cd elements that have a title attribute with value equal to the value of the current node's ref attribute.

Example :

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

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="catalog/cd/artist">
Current node: <xsl:value-of select="current()"/>
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


document() Function

Usage of document() : The document() function is used to access nodes in an external XML document. The external XML document must be valid and parsable.
One way to use this function is to look up data in an external document. For example we want to find the Celsius value from a Fahrenheit value and we refer to a document that contains some pre-computed results:
<xsl:value-of select="document('celsius.xml')/celsius/result[@value=$value]"/>


element-available() Function

Usage and Example of element-available() : The element-available() function returns a Boolean value that indicates whether the element specified is supported by the XSLT processor.
This function can only be used to test elements that can occur in a template body. These elements are:
  1. xsl:apply-imports
  2. xsl:apply-templates
  3. xsl:attributes
  4. xsl:call-template
  5. xsl:choose
  6. xsl:comment
  7. xsl:copy
  8. xsl:copy-of
  9. xsl:element
  10. xsl:fallback
  11. xsl:for-each
  12. xsl:if
  13. xsl:message
  14. xsl:number
  15. xsl:processing instruction
  16. xsl:text
  17. xsl:value-of
  18. xsl:variable
Example :

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

<xsl:template match="/">
<html>
<body>
<xsl:choose>
<xsl:when test="element-available('xsl:comment')">
<p>xsl:comment is supported.</p>
</xsl:when>
<xsl:otherwise>
<p>xsl:comment is not supported.</p>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="element-available('xsl:delete')">
<p>xsl:delete is supported.</p>
</xsl:when>
<xsl:otherwise>
<p>xsl:delete is not supported.</p>
</xsl:otherwise>
</xsl:choose>
</body>
</html>
</xsl:template>

</xsl:stylesheet>



format-number() Function

Usage and Example of function-number() : The format-number() function is used to convert a number into a string.

Example :

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

<xsl:template match="/">
<html>
<body>
<xsl:value-of select='format-number(500100, "#")' />
<br />
<xsl:value-of select='format-number(500100, "0")' />
<br />
<xsl:value-of select='format-number(500100, "#.00")' />
<br />
<xsl:value-of select='format-number(500100, "#.0")' />
<br />
<xsl:value-of select='format-number(500100, "###,###.00")' />
<br />
<xsl:value-of select='format-number(0.23456, "#%")' />
</body>
</html>
</xsl:template>

</xsl:stylesheet>




function-available() Function

Usage and Example of function-available(): The function-available() function returns a Boolean value that indicates whether the function specified is supported by the XSLT processor.

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

<xsl:template match="/">
<html>
<body>
<xsl:choose>
<xsl:when test="function-available('sum')">
<p>sum() is supported.</p>
</xsl:when>
<xsl:otherwise>
<p>sum() is not supported.</p>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="function-available('current')">
<p>current() is supported.</p>
</xsl:when>
<xsl:otherwise>
<p>current() is not supported.</p>
</xsl:otherwise>
</xsl:choose>
</body>
</html>
</xsl:template>

</xsl:stylesheet>




generate-id() Function

Usage and Example of generate-id() : The generate-id() function returns a string value that uniquely identifies a specified node. If the node-set specified is empty, an empty string is returned. If you omit the node-set parameter, it defaults to the current node.

Example :

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

<xsl:template match="/">
<html>
<body>
<h3>Artists:</h3>
<ul>
<xsl:for-each select="catalog/cd">
<li>
<a href="#{generate-id(artist)}">
<xsl:value-of select="artist" /></a>
</li>
</xsl:for-each>
</ul>
<hr />
<xsl:for-each select="catalog/cd">
Artist: <a name="{generate-id(artist)}">
<xsl:value-of select="artist" /></a>
<br />
Title: <xsl:value-of select="title" />
<br />
Price: <xsl:value-of select="price" />
<hr />
</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


key() Function

Usage and Example of key() : The key() function returns a node-set from the document, using the index specified by an <xsl:key> element.

Example :

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

<xsl:key name="cdlist" match="cd" use="title" />

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="key('cdlist', 'Empire Burlesque')">
<p>
Title: <xsl:value-of select="title" />
<br />
Artist: <xsl:value-of select="artist" />
<br />
Price: <xsl:value-of select="price" />
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


system-property() Function

Usage and Example of system-property(): The system-property() function returns the value of the system property specified by the name.

System properties in the XSLT namespace:
  • xsl:version - The version of XSLT implemented by the processor
  • xsl:vendor - The vendor of the XSLT processor
  • xsl:vendor-url - The URL identifying the vendor of the XSLT processor
Example :

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

<xsl:template match="/">
<html>
<body>
<p>
Version:
<xsl:value-of select="system-property('xsl:version')" />
<br />
Vendor:
<xsl:value-of select="system-property('xsl:vendor')" />
<br />
Vendor URL:
<xsl:value-of select="system-property('xsl:vendor-url')" />
</p>
</body>
</html>
</xsl:template>

</xsl:stylesheet>



unparsed-entity-uri() Function

Usage and Example of unparsed-entity-uri() : The unparsed-entity-uri() function returns the URI of an unparsed entity. The name of the entity must match the passed argument. If there is no such entity an empty string is returned.

If the DTD contains the following declaration:
<!ENTITY pic SYSTEM "http://www.abc.com/hello.jpg" NDATA JPEG>
the following expression:
unparsed-entity-uri('pic')
will return the URI for the file "hello.jpg".

In the following line we show an Example for Create HTML file from xml and xslt files :


To illustrate this I have given an example given below :

Create HTML from XSLT

Saturday 25 August 2012

How can I show Messagebox with HTML Code


In HTML we cannot use not use 'vbscript' command 'msgbox' to display the messagebox or any other window message commands, becuse html viewed in web browser. So thewindow message not display on It.

We can display message on web form by use the following code.

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
     alert("Hello! I am an alert box!");
}
</script>
</head>
<body>
<input type="button" onclick="myFunction()" value="Show alert box" />
</body>
</html>

In above html code we type a 'javascript functon' named 'myFunction()'. We use 'alert' command in this function. This command is used to display message on Web Browser. 

Playing Videos in HTML



To Play movie in HTML File Pls. use the following steps
    1. First create a folder i.e. we create a folder named  "Play movie with html code" 
    2. Now add two files in this folder in which one file is movie file which is of any format like '.mp4', '..webm','.ogg' etc. and second file is '.swf' format. We used two files 'movie.ogg' and 'movie.swf'
    3. Now open a notepad file and paste the following code


  <!DOCTYPE html>
  <html>
  <body>
  <video width="320" height="240" controls="controls" autoplay="autoplay">
  <source src="movie.ogg" type="video/ogg" />
  <source src="movie.mp4" type="video/mp4" />
  <source src="movie.webm" type="video/webm" />
  <object data="movie.mp4" width="320" height="240">
  <embed width="320" height="240" src="movie.swf" />
  </object>
  </video>
  </body>
  </html>

             Now saved the above file with any name along with .html' extension. i.e. we used 'playmovie.html'

             4     Now when we browse the 'playmovie.html' file in any browser then it play your movie.

Video play with HTML code



Twitter Bird Gadget