Skip to content

Instantly share code, notes, and snippets.

@virtual
Created September 23, 2020 21:04
Show Gist options
  • Select an option

  • Save virtual/2d1001b24779daeed4ffc3684dc7fd07 to your computer and use it in GitHub Desktop.

Select an option

Save virtual/2d1001b24779daeed4ffc3684dc7fd07 to your computer and use it in GitHub Desktop.
OU Campus Canonical common.xsl
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#160;">
<!ENTITY lsaquo "&#8249;">
<!ENTITY rsaquo "&#8250;">
<!ENTITY laquo "&#171;">
<!ENTITY raquo "&#187;">
<!ENTITY copy "&#169;">
<!ENTITY apos "&#39;">
<!ENTITY quot "&#34;">
<!ENTITY mdash "&#8212;">
<!ENTITY lsquo "&#8216;">
<!ENTITY middot "&#183;">
]>
<!--
Checks for the following in the PCF:
<ouc:properties label="config">
<parameter name="canonical" dependency="no" type="filechooser" group="Everyone" prompt="Canonical Link" alt="Canonical link override. Defaults to self."></parameter>
</ouc:properties>
-->
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ou="http://omniupdate.com/XSL/Variables"
xmlns:fn="http://omniupdate.com/XSL/Functions"
xmlns:ouc="http://omniupdate.com/XSL/Variables"
exclude-result-prefixes="xsl xs ou fn ouc">
<xsl:template match="/document">
<xsl:call-template name="page-directive" />
<html lang="en">
<xsl:text disable-output-escaping="yes">&lt;</xsl:text>!--<xsl:text disable-output-escaping="yes">&lt;</xsl:text>![endif]--<xsl:text disable-output-escaping="yes">&gt;</xsl:text>
<head>
<xsl:variable name="pageurl" select="concat(string-join(remove(tokenize(substring($ou:httproot, 1), '/'), count(tokenize(substring($ou:httproot, 1), '/'))), '/'),$ou:path)" />
<script type="text/javascript">
var page_url="<xsl:value-of select="$pageurl"/>";
</script>
<xsl:call-template name="header-canonical">
<xsl:with-param name="pageurl" select="$pageurl"/>
</xsl:call-template>
</head>
<body>...</body>
</html>
<!-- end html -->
</xsl:template>
<xsl:template name="header-canonical">
<xsl:param name="pageurl"/>
<xsl:choose>
<xsl:when test="not(ou:pcf-param('canonical') = '')">
<xsl:choose>
<xsl:when test="(starts-with(ou:pcf-param('canonical'), 'http'))">
<!-- starts with http/s -->
<link rel="canonical" href="{ou:pcf-param('canonical')}"/>
</xsl:when>
<xsl:otherwise>
<link rel="canonical" href="{concat(string-join(remove(tokenize(substring($ou:httproot, 1), '/'), count(tokenize(substring($ou:httproot, 1), '/'))), '/'), ou:pcf-param('canonical'))}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<link rel="canonical" href="{$pageurl}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment