Commit 2d14a7ce authored by Dave Reid's avatar Dave Reid

#489360 by Dave Reid: Backported XSL translation and location fixes.

parent 3eae2f01
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Google Sitmaps Stylesheets (GSStylesheets)
Project Home: http://sourceforge.net/projects/gstoolbox
Copyright (c) 2005 Baccou Bonneville SARL (http://www.baccoubonneville.com)
License http://www.gnu.org/copyleft/lesser.html GNU/LGPL -->
<xsl:stylesheet version="2.0"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="utf-8" indent="yes"/>
<!-- Root template -->
<xsl:template match="/">
<html>
<head>
<title>Site map file</title>
<link href="/sites/all/modules/xmlsitemap/gss/gss.css" type="text/css" rel="stylesheet"/>
<script src="/sites/all/modules/xmlsitemap/gss/gss.js"></script>
<title>Sitemap file</title>
<script type="text/javascript" src="[xsl-js]"></script>
<link href="[xsl-css]" type="text/css" rel="stylesheet"/>
</head>
<!-- Store in $fileType if we are in a sitemap or in a siteindex -->
<xsl:variable name="fileType">
<xsl:choose>
<xsl:when test="//sitemap:url">sitemap</xsl:when>
<xsl:otherwise>siteindex</xsl:otherwise>
<xsl:when test="//sitemap:url">sitemap</xsl:when>
<xsl:otherwise>siteindex</xsl:otherwise>
</xsl:choose>
</xsl:variable>
......@@ -28,7 +31,7 @@
<body onLoad="initXsl('table0','{$fileType}');">
<!-- Text and table -->
<h1 id="head1">Site map file:</h1>
<h1 id="head1">Sitemap file</h1>
<xsl:choose>
<xsl:when test="$fileType='sitemap'"><xsl:call-template name="sitemapTable"/></xsl:when>
<xsl:otherwise><xsl:call-template name="siteindexTable"/></xsl:otherwise>
......@@ -39,11 +42,11 @@
<!-- siteindexTable template -->
<xsl:template name="siteindexTable">
<h2>Number of site maps in this index: <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"></xsl:value-of></h2>
<h2>Number of sitemaps in this index: <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"></xsl:value-of></h2>
<p class="sml">Click on the table headers to change sorting.</p>
<table border="1" width="100%" class="data" id="table0">
<tr class="header">
<td>Site map URL</td>
<td>Sitemap URL</td>
<td>Last modification date</td>
</tr>
<xsl:apply-templates select="sitemap:sitemapindex/sitemap:sitemap">
......@@ -54,13 +57,13 @@
<!-- sitemapTable template -->
<xsl:template name="sitemapTable">
<h2>Number of URLs in this site map: <xsl:value-of select="count(sitemap:urlset/sitemap:url)"></xsl:value-of></h2>
<h2>Number of URLs in this sitemap: <xsl:value-of select="count(sitemap:urlset/sitemap:url)"></xsl:value-of></h2>
<p class="sml">Click on the table headers to change sorting.</p>
<table border="1" width="100%" class="data" id="table0">
<tr class="header">
<td>Site map URL</td>
<td>URL location</td>
<td>Last modification date</td>
<td>Change freq.</td>
<td>Change frequency</td>
<td>Priority</td>
</tr>
<xsl:apply-templates select="sitemap:urlset/sitemap:url">
......@@ -92,5 +95,4 @@
<td><xsl:value-of select="sitemap:lastmod"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
......@@ -164,6 +164,12 @@ function xmlsitemap_menu() {
);
}
}
$items['sitemap.xsl'] = array(
'page callback' => 'xmlsitemap_output_xsl',
'access arguments' => $access_content,
'type' => MENU_CALLBACK,
'file' => 'xmlsitemap.pages.inc',
);
return $items;
}
......@@ -414,4 +420,3 @@ function xmlsitemap_user_form_fieldset() {
/**
* @} End of "addtogroup xmlsitemap".
*/
......@@ -167,8 +167,8 @@ function _xmlsitemap_check_cache_files() {
*/
function _xmlsitemap_create_cache_chunk($fp, $chunk_size, $chunk = 0) {
fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>' . "\n");
if ($xsl = _xmlsitemap_xsl()) {
fwrite($fp, '<?xml-stylesheet type="text/xsl" href="' . $xsl . '" ?>' . "\n");
if (variable_get('xmlsitemap_use_stylesheet', FALSE)) {
fwrite($fp, '<?xml-stylesheet type="text/xsl" href="' . url('sitemap.xsl') . '" ?>' . "\n");
}
fwrite($fp, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n");
fwrite($fp, ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n");
......@@ -205,27 +205,6 @@ function _xmlsitemap_create_cache_chunk($fp, $chunk_size, $chunk = 0) {
fwrite($fp, '</urlset>');
}
/**
* Determine path for a xml stylesheet.
*
* @return
* - The stylesheet path or FALSE.
*/
function _xmlsitemap_xsl() {
if (variable_get('xmlsitemap_use_stylesheet', FALSE)) {
$paths = array(
variable_get('xmlsitemap_cache_directory', file_directory_path() . '/xmlsitemap') . '/gss.xsl',
drupal_get_path('module', 'xmlsitemap') . '/gss/gss.xsl',
);
foreach ($paths as $path) {
if (file_exists($path)) {
return base_path() . $path;
}
}
}
return FALSE;
}
/**
* Create the cache files containing the sitemap.
*
......@@ -247,8 +226,8 @@ function _xmlsitemap_create_cache_files() {
return FALSE;
}
fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>' . "\n");
if ($xsl = _xmlsitemap_xsl()) {
fwrite($fp, '<?xml-stylesheet type="text/xsl" href="' . $xsl . '" ?>' . "\n");
if (variable_get('xmlsitemap_use_stylesheet', FALSE)) {
fwrite($fp, '<?xml-stylesheet type="text/xsl" href="' . url('sitemap.xsl') . '" ?>' . "\n");
}
fwrite($fp, '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n");
fwrite($fp, ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n");
......@@ -290,6 +269,36 @@ function _xmlsitemap_create_cache_files() {
return TRUE;
}
/**
* Output an XML transformation file for the sitemap XML.
*/
function xmlsitemap_output_xsl() {
// Read the XSL content from the file.
$module_path = drupal_get_path('module', 'xmlsitemap');
$xsl_content = file_get_contents($module_path . '/gss/gss.xsl');
// Make sure the strings in the XSL content are translated properly.
$replacements = array(
'Sitemap file' => t('Sitemap file'),
'Number of sitemaps in this index' => t('Number of sitemaps in this index'),
'Click on the table headers to change sorting.' => t('Click on the table headers to change sorting.'),
'Sitemap URL' => t('Sitemap URL'),
'Last modification date' => t('Last modification date'),
'Number of URLs in this sitemap' => t('Number of URLs in this sitemap'),
'URL location' => t('URL location'),
'Change frequency' => t('Change frequency'),
'Priority' => t('Priority'),
'[xsl-js]' => base_path() . $module_path . '/gss/gss.js',
'[xsl-css]' => base_path() . $module_path . '/gss/gss.css',
);
$xsl_content = strtr($xsl_content, $replacements);
// Output the XSL content.
drupal_set_header('Content-type: application/xml; charset=utf-8');
drupal_set_header('X-Robots-Tag: noindex, follow');
echo $xsl_content;
}
/**
* @} End of "addtogroup xmlsitemap".
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment