Skip to content

Instantly share code, notes, and snippets.

@tiarno
Created April 30, 2019 12:16
Show Gist options
  • Save tiarno/094ca5dc7f9c3ae560af9ace975881d3 to your computer and use it in GitHub Desktop.
Save tiarno/094ca5dc7f9c3ae560af9ace975881d3 to your computer and use it in GitHub Desktop.
XSL for Creating an Appendix with wkhtmltopdf
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:outline="http://wkhtmltopdf.org/outline"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
indent="yes" />
<xsl:template match="outline:outline">
<html>
<head>
<title>Appendix A</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
h1 {
text-align: center;
font-size: 20px;
font-family: arial;
}
div {border-bottom: 1px dashed rgb(200,200,200);}
span {float: right;}
li {list-style: none;}
ul {
font-size: 20px;
font-family: arial;
}
ul ul {font-size: 80%; }
ul {padding-left: 0em;}
ul ul {padding-left: 1em;}
a {text-decoration:none; color: #287eab;}
</style>
</head>
<body>
<h1>Appendix A</h1>
<ul><xsl:apply-templates select="outline:item/outline:item"/></ul>
</body>
</html>
</xsl:template>
<xsl:template name="paramname">
<xsl:param name="str" />
<xsl:choose>
<xsl:when test="contains($str,':')">
<xsl:value-of select="substring-after($str,':')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$str" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="outline:item/outline:item">
<li>
<xsl:if test="@title!=''">
<div>
<a>
<xsl:if test="@link">
<xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
</xsl:if>
<xsl:call-template name="paramname">
<xsl:with-param name="str" select="normalize-space(@title)" />
</xsl:call-template>
</a>
<span> <xsl:value-of select="@page" /> </span>
</div>
</xsl:if>
<!--
<ul>
<xsl:comment>added to prevent self-closing tags in QtXmlPatterns</xsl:comment>
<xsl:apply-templates select="outline:item"/>
</ul>
-->
</li>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment