algorithms (22) Design Patterns (20) java (19) linux (14) Snippet (13) service mix (6) soa (4)



Basics Of XSL



    <xsl:template> is a set of rules to be applied when a node is matched
    match="/"          is used along with the template tag to specify on which node to apply the template on , if it is “/” it has to be applied on the entire document.
    <xsl:value-of> used to get the value of a tag.
    <xsl:for-each> used to iterate over a list of nodes
    filter the output  
    <xsl:sort>       used to sort the nodes based on a tag
    <xsl:if> used to test the condition on a node

Sample XML

<?xml version="1.0" encoding="UTF-8"?>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>

XSL To Transform

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="" xmlns:fo="" xmlns:xs="" xmlns:fn="">
<xsl:template match="/">
<table border="1">
<td>Title</td> <td>genre</td> <td>author</td> <td>price</td>
<xsl:for-each select="/catalog/book">
<xsl:sort select="title"/>
<xsl:value-of select="./title"/>
<xsl:value-of select="./genre"/>
<xsl:value-of select="./author"/>
<xsl:if test="price &gt; 10">
<font color="Red"></font>
<xsl:value-of select="./price"/>



Maeve AscendantFantasyCorets, Eva5.95
Midnight RainFantasyRalls, Kim5.95
XML Developer's GuideComputerGambardella, Matthew44.95

No comments:

Post a Comment

Search 24 Bytes