Skip to content

Instantly share code, notes, and snippets.

@arvinwiyono
Created September 20, 2016 03:32
Show Gist options
  • Save arvinwiyono/ed71ed6f86b8c881c490355baeb70d27 to your computer and use it in GitHub Desktop.
Save arvinwiyono/ed71ed6f86b8c881c490355baeb70d27 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/Book">
<!DOCTYPE html>
<html>
<head>
<title>My First XSLT exercise</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></link>
</head>
<body>
<h1>Authors</h1>
<ul>
<xsl:for-each select="Authors/Author">
<li>
<xsl:value-of select="."></xsl:value-of>
</li>
</xsl:for-each>
</ul>
<h1>Chapters</h1>
<ul>
<xsl:for-each select="Chapters/*">
<li>
<xsl:apply-templates select="current()"></xsl:apply-templates>
<xsl:if test="current()/* ">
<ul>
<xsl:for-each select="*">
<li>
<xsl:apply-templates select="."></xsl:apply-templates >
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="Picture">
<img>
<xsl:attribute name="src">
<xsl:value-of select="@url"></xsl:value-of>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="current()"></xsl:value-of>
</xsl:attribute>
</img>
</xsl:template>
<xsl:template match="Chapter">
<xsl:value-of select="."></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment