Is an XSLT processor bundled in WebLogic Server? |
Yes, an XSLT processor is bundled in WebLogic Server, It is based on Apache\'s Xalan 2.0.1 processor, in WebLogic Server 6.1. |
what is the XSLT?
|
XSLT stands for Extensible Stylesheet Language Transformations(XSLT).This is developed by World Wide Web Consortium(W3C).This is written in XML.We use XSLT when we want to transform an XML document into the oter XML document.
Generally we use XSLT when we want to make transformation from a XML document into another XML document,Convert a XML document into the HTML or XHTML document, creating dynamic web pages, can convert an XML document into PDF document.
We saved the XSLT file by using .xsl or .xslt extension.Recent version of XSLT is XSLT2.0 launched at 23rd Jan 2007.It is a part of XSL.Editor od first version of XSLT are James Clark. |
how we compare XSLT and XPath?? |
Some comparison b/w XSLT and XPath and given below:
- XSLT is depends upon W3C XPath language.Which is use to identify subset of source document tree.XPath is also used to provide the function range.
- Both XSLT and XPath published at same time than we can say that XSLT2.0 trusts on XPath2.0 and XSLT1.0 trusts on XPath1.0.
|
How we compare XSLT and XQuery?
|
How to transform an XML document into another XML document? |
Here,I given you a exampl which show you how to transform an XML document into another XML document.
Example:
<?xml version=\"1.0\" ?> <xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"> <xsl:output method=\"xml\" indent=\"yes\"/> <xsl:template match=\"/persons\"> <root> <xsl:apply-templates select=\"person\"/> </root> </xsl:template> <xsl:template match=\"person\"> <name username=\"{@username}\"> <xsl:value-of select=\"name\" /> </name> </xsl:template> </xsl:stylesheet> We can tranform above XML document into another document like that, <?xml version=\"1.0\" encoding=\"UTF-8\"?> <root> <name username=\"Abhi\">Abhi</name> <name username=\"Sudi\">Sudi</name> </root> |
How to transform an XML into XHTML? |
Below, I write an example which show you how transform an XML into XHTML.
Example:
<?xml version=\"1.0\" encoding=\"UTF-8\"?> <xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns=\"http://www.w3.org/1999/xhtml\"> <xsl:output method=\"html\"/> <xsl:template match=\"/persons\"> <html> <head> <title>Test an XML Example</title> </head> <body> <h1>Persons</h1> <ul> <xsl:apply-templates select=\"person\"> <xsl:sort select=\"family-name\" /> </xsl:apply-templates> </ul> </body> </html> </xsl:template> <xsl:template match=\"person\"> <li> <xsl:value-of select=\"family-name\"/> <xsl:text>, </xsl:text> <xsl:value-of select=\"name\"/> </li> </xsl:template> </xsl:stylesheet> To get output on the XHTML we write like that,
<?xml version=\"1.0\" encoding=\"UTF-8\"?> <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> <title>Test an XML Example</title> </head> <body> <h1>Persons</h1> <ul> <li>gupta, Abhi</li> <li>jain, sudi</li> </ul> </body> </html>
|
How you define template in XSLT? |
When XSL style sheet has one or more set of rules are told as templates. We used <xsl:template> element to create templates.
We can attach a template with an XML document by using match attribute.The match attribute value is an XPath exprssion.Like: match=\"/\" use to define whole document.
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> <h2> Book Collection </h2> <table border=\"1\"> <tr bgcolor=\"#9acd32\"> <th>Title</th> <th>Author</th> </tr> <tr> <td>.</td> <td>.</td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet>
|
How to use element in XSLT? |
We use <xsl:value-of> element to extract the value of an selected XML 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:template match=\"/\"> <html> <body> <h2>Book Collection</h2> <table border=\"1\"> <tr bgcolor=\"#9acd32\"> <th>Title</th> <th>Author</th> </tr> <tr> <td><xsl:value-of select=\"catalog/book/author\"/></td> <td><xsl:value-of select=\"catalog/book/author\"/></td> </tr> </table> </body> </html> </xsl:template> </xsl:stylesheet> |
How to use element in XSLT? |
Using <xsl:for-each> element we can enable the looping in XSLT.
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> <h2>Book Collection</h2> <table border=\"1\"> <tr bgcolor=\"#9acd32\"> <th>Title</th> <th>Author</th> </tr> <xsl:for-each select=\"catalog/book\"> <tr> <td><xsl:value-of select=\"title\"/></td> <td><xsl:value-of select=\"author\"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
|
How to use filtering in XSLT? |
We can filter the XNL output by using filter operators.Some Legal filter operators are given below: 1.=(equal to) 2.!=(not equal to) 3.<(less than) 4.>(greater than)
I have given you a example. In this I have uses \'=\' equal to filer operation.
<?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> <h2>Book Collection</h2> <table border=\"1\"> <tr bgcolor=\"#9acd32\"> <th>Title</th> <th>Author</th> </tr> <xsl:for-each select=\"catalog/book[author=\'Yashwant Kanetkar\']\"> <tr> <td><xsl:value-of select=\"title\"/></td> <td><xsl:value-of select=\"author\"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Above, XML document will give output related to author Yashwant Kanetkar. |
How to use element in XSLT? |
We use <xsl:sort> element to sort the given output. 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> <h2>Book Collection</h2> <table border=\"1\"> <tr bgcolor=\"#9acd32\"> <th>Title</th> <th>Author</th> </tr> <xsl:for-each select=\"catalog/book\"> <xsl:sort select=\"author\"/> <tr> <td><xsl:value-of select=\"title\"/></td> <td><xsl:value-of select=\"author\"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> |
How to use element in XSLT? |
Using <xsl:if> element we can test the content of an XSL document. Syntax:
<xsl:if test=\"expression\"> ...Write here output it will dispay when condition is true... </xsl:if> I have given you example to use of <xsl:if> element. <?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> <h2>Book Collection</h2> <table border=\"1\"> <tr bgcolor=\"#9acd32\"> <th>Title</th> <th>Author</th> </tr> <xsl:for-each select=\"catalog/book\"> <xsl:if test=\"price > 150\"> <tr> <td><xsl:value-of select=\"title\"/></td> <td><xsl:value-of select=\"author\"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> It will give the title of book with related author which book cost greater than 150. |
How to use element inXSLT?
|
When we want to use <xsl:choose> element in XSL file.Than we use <xsl:when> and<xsl:otherwise> inside the <xsl:choose> element.Using them we can show multiple conditional test cases.
Syntax:
<xsl:choose> <xsl:when test=\"expression\"> ... Than gives that output ... </xsl:when> <xsl:otherwise> ... Than gives that output .... </xsl:otherwise> </xsl:choose> |
Give an example of XSL file with choose condition? |
Using choose conditon in XSL file we can add some multi conditional test cases.
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> <h2>Book Collection</h2> <table border=\"1\"> <tr bgcolor=\"#9acd32\"> <th>Title</th> <th>Author</th> </tr> <xsl:for-each select=\"catalog/book\"> <tr> <td><xsl:value-of select=\"title\"/></td> <xsl:choose> <xsl:when test=\"price > 150\"> <td bgcolor=\"#ff00ff\"> <xsl:value-of select=\"author\"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select=\"author\"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
In the above program we display those entries of Author column with pink color WHEN book price is higher than 150. |
How to use element in XSLT?
|
Using <xsl:apply-template>element we can apply a template on current element or can apply on the child nodes of current 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:template match=\"/\"> <html> <body> <h2>Book Collection</h2> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match=\"book\"> <p> <xsl:apply-templates select=\"title\"/> <xsl:apply-templates select=\"author\"/> </p> </xsl:template> <xsl:template match=\"title\"> Title: <span style=\"color:#ff0000\"> <xsl:value-of select=\".\"/></span> <br /> </xsl:template> <xsl:template match=\"author\"> Author: <span style=\"color:#00ff00\"> <xsl:value-of select=\".\"/></span> <br /> </xsl:template> </xsl:stylesheet> |
How you define functions in XSLT? |
XSLT has more than 100 build-in functions.This functions are made for string values,date and time comparison,numeric values,sequence manipulation, Node and QName and boolean variable etc.
We can find out the XSLT function namespace from http://www.w3.org/2005/02/xpath-functions I have given you some XSLT build-in functions. current(),document(),element-variable(),function-variable(),key,gererated-id() etc. |