У меня есть карта сайта xml:
<urlset>
<url>
<loc>http://www.somedomain.com</loc>
<changefreq>monthly</changefreq>
<priority>1</priority>
</url>
</urlset>
Я создаю его, используя xslt
, и мне нужно urlset
, чтобы иметь атрибуты пространства имен:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
Как их добавить?
Это мой xslt
фрагмент:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:element name = "urlset">
<!-- xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"-->
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
</xsl:call-template>
</xsl:element>
</xsl:template>
EDIT
Это отредактированный фрагмент после @ michael.hor257k ответа:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="currentPage"/>
<!-- update this variable on how deep your site map should be -->
<xsl:variable name="maxLevelForSitemap" select="6"/>
<xsl:template match="/">
<xsl:call-template name="urlset"> </xsl:call-template>
</xsl:template>
<xsl:template name="urlset">
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<!-- more code here -->
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
</xsl:call-template>
</urlset>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
<xsl:for-each select="$parent/* [@isDoc and @level <= $maxLevelForSitemap and (umbracoNaviHide != '1' or not(umbracoNaviHide))]">
<xsl:if test="@id > 0">
<xsl:if test="not(umbracoRedirect) or umbracoRedirect = ''">
<xsl:element name="url">
<xsl:element name="loc">
<xsl:variable name="url" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))" />
<xsl:value-of select="concat($url,umbraco.library:NiceUrl(@id))" />
</xsl:element>
<xsl:element name="changefreq">
<xsl:if test="sitemapChange != ''">
<xsl:value-of select="sitemapChange" />
</xsl:if>
<xsl:if test="not(sitemapChange) or sitemapChange = ''">
<xsl:choose>
<xsl:when test="@level <= 2">weekly</xsl:when>
<xsl:when test="@level >= 3">monthly</xsl:when>
<xsl:when test="@level >= 4">weekly</xsl:when>
<xsl:otherwise>yearly</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:element>
<xsl:element name="priority">
<xsl:if test="not(sitemapChange) or sitemapChange = ''">
<xsl:choose>
<xsl:when test="@level <= 2">1</xsl:when>
<xsl:when test="@level >= 3">0.9</xsl:when>
<xsl:when test="@level >= 4">0.8</xsl:when>
<xsl:otherwise>0.7</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:element>
</xsl:element>
</xsl:if>
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Тем не менее выводит url
с пустым пространством имен xmlns.
РЕДАКТИРОВАТЬ 2
Даже если я сделаю простой код, как здесь:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:call-template name="urlset" />
</xsl:template>
<xsl:template name="urlset">
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<xsl:call-template name="url">
</xsl:call-template>
</urlset>
</xsl:template>
<xsl:template name="url">
<url>
</url>
</xsl:template>
</xsl:stylesheet>
Я все еще получаю пустое пространство имен в url
:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<url xmlns="" />
</urlset>
Что неверно.