08/12/2012 00:51

Examle taken from Xslt W3 Schools: https://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_apply

xslt file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"

<xsl:template match="/">
  <h2>My CD Collection</h2> 

<!--call all templates define below. Note: If some templates is applied to parent node, it's needed to apply-templates inside to continue, either it's stopped on parent level as seen in 'cd' template-->

<xsl:template match="cd">
    <xsl:apply-templates select="title"/>
    <xsl:apply-templates select="artist"/>

<xsl:template match="title">
  Title: <span style="color:#ff0000">
  <xsl:value-of select="."/></span>
  <br />

<xsl:template match="artist">
  Artist: <span style="color:#00ff00">
  <xsl:value-of select="."/></span>
  <br />



Title: Empire Burlesque
Artist: Bob Dylan

Title: Hide your heart
Artist: Bonnie Tyler



xml source:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
  <title>Empire Burlesque</title>
  <artist>Bob Dylan</artist>
  <title>Hide your heart</title>
  <artist>Bonnie Tyler</artist>
  <company>CBS Records</company>