Xalan does not do XSLT 2.0 so if you want to use XSLT 2.0 then try Saxon
(
http://saxon.sourceforge.net/) or Gestalt
(
http://gestalt.sourceforge.net/) or AltovaXML
(
http://www.altova.com/altovaxml.html).
If you want to use PHP then I think PHP supports EXSLT so you could try
to usehttp://
www.exslt.org/str/functions/tokenize/index.html
Thank you very much, Martin
It's now working fine with Altova XML Spy and Saxon9 as external XSLT
parser:
http://216.239.59.104/search?q=cach...spy&hl=es&ct=clnk&cd=6&gl=es&client=firefox-a
There are only 2 little issues left:
My XML input is:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="
http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>
http://localhost/index.php/index.php/ezwebin_site/Rutas-de-
verano-en-España</loc>
<lastmod>2008-03-13</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>
http://localhost/index.php/index.php/ezwebin_site/Rutas/El-
Camino-de-Santiago-en-el-Sobrarbe</loc>
<lastmod>2008-02-12</lastmod>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
</url>
</urlset>
Your XSLT 2.0 is:
<xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns:news="
http://www.google.com/schemas/sitemap-news/0.9"
xmlns:sm="
http://www.sitemaps.org/schemas/sitemap/0.9" exclude-result-
prefixes="sm" version="2.0">
<xsl
utput method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sm:url">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
< < <xsl:value-of select="sm:lastmod"/>
</ < <xsl:value-of select="for $s in tokenize(sm:loc, '/')[position()
> 5]
return tokenize($s, '[\-/]')[string-length(.)
> 3]" separator=", "/>
</ </ </xsl:copy>
</xsl:template>
</xsl:stylesheet>
The output is:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="
http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>
http://localhost/index.php/index.php/ezwebin_site/Rutas-de-
verano-en-España</loc>
<lastmod>2008-03-13</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
<xmlns:news="
http://www.google.com/schemas/sitemap-news/
0.9">
< <Rutas, verano, España</ </ </url>
<url>
<loc>
http://localhost/index.php/index.php/ezwebin_site/Rutas/El-
Camino-de-Santiago-en-el-Sobrarbe</loc>
<lastmod>2008-02-12</lastmod>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
<xmlns:news="
http://www.google.com/schemas/sitemap-news/
0.9">
< <Rutas, Camino, Santiago, rt</
</ </url>
</urlset>
But I need an output like defined by News Sitemap Protocol:
http://www.google.com/support/webmasters/bin/answer.py?answer=42738
So there are 2 things left:
1- <lastmod> tags should dissapear from <url> outputs because a
<tag has been defined already.
2- xmlns:news namespace should dissapear from <tags and it
should be taken to the <urlset xmlns="
http://www.sitemaps.org/schemas/
sitemap/0.9"> tag in the header.
A good output file would be:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="
http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:news="
http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>
http://localhost/index.php/index.php/ezwebin_site/Rutas-de-
verano-en-España</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
< < <Rutas, verano, España</ </ </url>
<url>
<loc>
http://localhost/index.php/index.php/ezwebin_site/Rutas/El-
Camino-de-Santiago-en-el-Sobrarbe</loc>
<changefreq>weekly</changefreq>
<priority>0.7</priority>
< < <Rutas, Camino, Santiago, rt</
</ </url>
</urlset>
Any idea ?