Created
October 4, 2019 23:54
-
-
Save pchatterjee/e8b4bfe2c465309affff9ef433ae8507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="html" encoding="utf-8" indent="yes"/> | |
<xsl:template match="/"> | |
<xsl:text disable-output-escaping="yes"><!DOCTYPE html> </xsl:text> | |
<html> | |
<head> | |
<title>Quotes XML -> HTML using XSLT example</title> | |
<style> | |
tr:nth-child(odd){ | |
background-color:#eeeeee; | |
} | |
table { | |
width:80%; | |
text-align:left; | |
margin: auto; | |
} | |
td { | |
vertical-align:top; | |
} | |
</style> | |
</head> | |
<body> | |
<table> | |
<tr> | |
<th>cat</th> | |
<th>text</th> | |
<th>name</th> | |
<th>dob</th> | |
<th>dod</th> | |
<th>wplink</th> | |
<th>wpimg</th> | |
</tr> | |
<xsl:for-each select="/quotes/quote"> | |
<tr> | |
<td><xsl:value-of select="./@cat"/></td> | |
<xsl:call-template name="tableBody"/> | |
</tr> | |
</xsl:for-each> | |
</table> | |
</body> | |
</html> | |
</xsl:template> | |
<xsl:template name="tableBody"> | |
<td><xsl:value-of select="./text"/></td> | |
<xsl:for-each select="./author/*"> | |
<xsl:choose> | |
<xsl:when test="local-name()='wplink'"> | |
<td> | |
<a> | |
<xsl:attribute name="href"> | |
<xsl:value-of select="."/> | |
</xsl:attribute> | |
<xsl:value-of select="."/> | |
</a> | |
</td> | |
</xsl:when> | |
<xsl:when test="local-name()='wpimg'"> | |
<td> | |
<img width="110"> | |
<xsl:attribute name="src"> | |
<xsl:value-of select="."/> | |
</xsl:attribute> | |
</img> | |
</td> | |
</xsl:when> | |
<xsl:otherwise> | |
<td> | |
<xsl:value-of select="."/> | |
</td> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:for-each> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment