<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
</xsl:stylesheet>
<xsl:stylesheet
----> Root elementxsl
----> Prefixversion="1.0"
----> There are several versions of XSLT that can be utilized.
A template consist of rules to apply to a specified xml element.
1. Type:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:template>
----> define a template.match="/"
----> this attribute reference our template to the root element of a XML document using the template.<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<?
----> Start of the reference tag.xml-stylesheet
----> Keyword use when you want to reference an XSL stylesheet in your xml document.type="text/xsl"
----> Pointing out that the document type we are referencing an to XSL document.href="style.xsl"?>
----> Adding the path of the XSL document using the HTML href attribute. Notice that the root was not specified since the XML document and the XSL document were on the same root.?>
----> End of the reference tag.<catalog>
<Game>
<title>Need For Speed</title>
<price>10.90</price>
<year>2015</year>
</Game>
<Game>
<title>Froza Horizon 2</title>
<price>10.90</price>
<year>2015</year>
</Game>
<Game>
<title>Tekken 6</title>
<price>10.90</price>
<year>2015</year>
</Game>
</catalog>
1. Between the body tags of the previously created style.XSL template, type:
<xsl:value-of select="title"/>
<xsl:value-of select="catalog/Game/title"/>
----> Extract the value of a specified XML element.select="catalog/Game/title"
----> specified XML elementcatalog/Game/title
----> XPATH code. XPATH is a language use to query XML. XPATH be soon covered in the intermediate XML tutorial on Channel R.
2. Save the xsl document.
3. Open the store.xml file using the Windows Internet Explorer web browser.
Try the following link: http://stackoverflow.com/questions/2904973/why-cant-i-get-xslt-to-work-in-chrome
For the sake of simplicity, I am using the Windows Internet Explorer web browser in this tutorial.
Result:
<xsl:for-each select="catalog/Game">
<xsl:for-each select="catalog/Game">
----> The XSL <xsl:for-each> select every XML element of the specified Game element.<xsl:value-of select="title"/>
<br/>
</xsl:for-each>
Your mission should you choose to accept it, is to apply all concepts that you learned in this tutorial using Notepad ++.