Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1 Elements in XSLT

ELEMENT xsl:apply-templates xsl:attribute xsl:choose xsl:comment xsl:copy xsl:copy-of xsl:element xsl:for-each xsl:if xsl:import xsl:include xsl:otherwise xsl:sort xsl:stylesheet xsl:template xsl:text xsl:transform xsl:value-of xsl:variable xsl:when

FUNCTION
Applies a template rule to the current element or to the current element's child nodes

Adds an attribute
Used in conjunction with <when> and <otherwise>to express multiple conditional tests

Creates a comment node in the result tree


Creates a copy of the current node (without child nodes and attributes)
Creates a copy of the current node (with child nodes and attributes)

Creates an element node in the output document


Loops through each node in a specified node set
Contains a template that will be applied only if a specified condition is true Imports the contents of one style sheet into another. An imported style sheet has lower precedence than the importing style sheet

Includes the contents of one style sheet into another.An included style sheet has the same precedence as the including style sheet

Specifies a default action for the <choose> element


Sorts the output

Defines the root element of a style sheet Rules to apply when a specified node is matched
Writes literal text to the output

Defines the root element of a style sheet Extracts the value of a selected node
Declares a local or global variable

Specifies an action for the <choose> element

2 HOW TO ACCESS THE CONTENT FROM THE ELEMENT


<?xml version ="1.0" ?> <?xml-stylesheet type="text/xsl" href="contoh1_1.xsl"?> <record> <book> <series>Utama</series> <title>12 Tugasan Utama</title> </book> </record> contoh1_1.xsl <?xml version = "1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version= "1.0"> <xsl:template match="/"> <html> <body> <b><h1><xsl:value-of select="//series"/></h1></b> <br/> <xsl:value-of select="//title"/> </body> </html> </xsl:template> </xsl:stylesheet> contoh1_2.xsl <?xml version = "1.0"?> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version= "1.0"> <xsl:template match="/"> <html> <body> <b><h1><xsl:value-of select="//title"/></h1></b> <br/> <xsl:value-of select="//series"/> </body> </html> </xsl:template> </xsl:stylesheet> contoh1_3.xsl <?xml version = "1.0"?> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version= "1.0"> <xsl:template match="/record/book/series"> <html> <body> <h1> <xsl:value-of select="name()"/> <xsl:text>:</xsl:text> <xsl:value-of select="."/> </h1> </body> </html> </xsl:template> </xsl:stylesheet>

3
contoh1_4.xsl <?xml version = "1.0"?> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version= "1.0"> <xsl:template match="book"> <b> <xsl:value-of select="."/> </b> </xsl:template> <xsl:template match="title"> <i> <xsl:value-of select="."/> </i> </xsl:template> </xsl:stylesheet> contoh1_5.xsl <?xml version = 1.0?> <xsl:stylesheet xmlns:xsl= http://www.w3.org/1999/XSL/Transform version= 1.0> <xsl:template match=book> <b><xsl:apply-templates select=series/></b> <b><xsl:apply-templates select=title/></b> </xsl:template> <xsl:template match=title> <i><xsl:value-of select=./></i> </xsl:template> </xsl:stylesheet> <html> <body> <b>Utama <i>12 tugas Utama</i></b> </body> </html>

Accessing the element many times


<?xml version = "1.0"?> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version= "1.0"> <xsl:template match="/"> <xsl:apply-templates select="/record/book/series" mode = "satu"/> <xsl:apply-templates select="/record/book/series" mode = "dua"/> </xsl:template> <xsl:template match="series" mode = "satu"> <i><xsl:value-of select="."/></i> </xsl:template> <xsl:template match="series" mode = "dua"> <b><xsl:value-of select="."/></b> </xsl:template> <xsl:template match="series"> <u><xsl:value-of select="."/></u> </xsl:template> </xsl:stylesheet>

4 HOW TO MANIPULATE WITH THE ATTRIBUTES


<?xml version =1.0 ?> <?xml-stylesheet type=text/xsl href=contoh2_1.xsl?> <record> <book> <series ke=1>Utama</series> <title>Orang-orang Norman</title> </book> <book isbn=a23532324> <series ke=1>Utama</series> <title>12 Tugasan Utama</title> </book> </record> contoh2_1.xsl <?xml version = 1.0?> <xsl:stylesheet xmlns:xsl= http://www.w3.org/1999/XSL/Transform version= 1.0> <xsl:template match=book> <xsl:apply-templates select=@isbn/> </xsl:template> <xsl:template match=book[@isbn]> <html> <body> <xsl:text>RECORD BOOK: </xsl:text> <p> <ul type=circle> <li>xsl:text>No. ISBN :</xsl:text> <i><xsl:value-of select=@isbn/></i> </li> <li>xsl:text>SERIES :</xsl:text> <i><xsl:value-of select=series/></i> </li> <li>xsl:text>TITLE :</xsl:text> <i><xsl:value-of select=title/></i> </li> </ul> </p> </body> </html> </xsl:template> </xsl:stylesheet>

5 xsl:for-each repeated process the element xsl:sort sorting


<?xml version =1.0 ?> <?xml-stylesheet type=text/xsl href=contoh3_1.xsl?> <record> <book isbn=a23532324> <series ke=1>Utama</series> <title>12 Tugasan Utama</title> <series ke=7>Utama</series> <title>Sabit Emas</title> <series ke=15>Utama</series> <title>Petaruhan Antara Kepala</title> <series ke=102>Utama</series> <title>Petualang ke Amerika</title> </book> </record> contoh3_1.xsl <?xml version = 1.0?> <xsl:stylesheet xmlns:xsl= http://www.w3.org/1999/XSL/Transform version= 1.0> <xsl:template match=/> <xsl:for-each select=//title> <xsl:sort order=descending select=./> <xsl:value-of select=./><br/> </xsl:for-each> </xsl:template> </xsl:stylesheet> contoh3_2.xsl <?xml version = 1.0?> <xsl:stylesheet xmlns:xsl= http://www.w3.org/1999/XSL/Transform version= 1.0> <xsl:template match=/> <xsl:apply-templates select=//title> <xsl:sort order=descending select=./> </xsl:apply-templates> </xsl:template> <xsl:template match=title> <xsl:value-of select=./><br/> </xsl:template> </xsl:stylesheet>

6 Sorting
<?xml version =1.0 ?> <?xml-stylesheet type=text/xsl href=contoh4_1.xsl?> <record> <book isbn=a23532324> <title series=Utama ke =1>12 Tugasan Utama</title> <title series =Utama ke=7>Sabit Emas</title> <title series =Utama ke=15>Pertaruhan </title> <title series=Utama ke=102>Amerika</title> </book> </record> contoh4_1.xsl <?xml version = 1.0?> <xsl:stylesheet xmlns:xsl= http://www.w3.org/1999/XSL/Transform version= 1.0> <xsl:template match=/> <xsl:for-each select=//title> <xsl:sort order=ascending data-type=text select=@ke/> <xsl:text>Series ke</xsl:text> <xsl:value-of select=@ke/> <xsl:text>:</xsl:text> <b><xsl:value-of select=./></b><br/> </xsl:for-each> </xsl:template> </xsl:stylesheet>

Contoh4_2.xsl <?xml version = 1.0?> <xsl:stylesheet xmlns:xsl= http://www.w3.org/1999/XSL/Transform version= 1.0> <xsl:template match=/> <xsl:for-each select=//title> <xsl:sort order=ascending data-type=number select=@ke/> <xsl:text>Series ke</xsl:text> <xsl:value-of select=@ke/> <xsl:text>:</xsl:text> <b><xsl:value-of select=./></b><br/> </xsl:for-each> </xsl:template> </xsl:stylesheet>

7 To Apply Axis to XSLT


<?xml version=1.0?> <?xml-stylesheet type=text/xsl href=contoh5_1.xsl?> <record> <friend no=a1> <name no=b1/> <name no=b2/> </friend> <friend no=a2> <name no=b3/> <name no=b4/> <address no=c1> <address no=c2/> </address> <name no=b5> <address no=c3/> </name> </friend> </record> contoh5_1.xsl <?xml version=1.0?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0> <xsl:template match=/> <TABLE border =1 cellpadding=6> <TR><TH colspan=2>Axis : following</TH></TR> < TR><TH>Elemen yang kita tentukan</TH> <TH>Elemen yang dipilih oleh : Axis</TH></TR> <xsl:for-each select=/record//*> <xsl:call-template name=panggil/> </xsl:for-each> </TABLE> </xsl:template> <xsl:template name=panggil> <TR> <TD> <xsl:value-of select=name()/> <xsl:text>id=</xsl:text> <xsl:value-of select=./@no/> </TD> <TD> <xsl:for-each select=following::*> <xsl:value-of select=./@no/> <xsl:text> </xsl:text> </xsl:for-each> </TD> </TR> </xsl:template> </xsl:stylesheet>

You might also like