【问题标题】:XSL and namespacesXSL 和命名空间
【发布时间】:2011-08-16 14:15:37
【问题描述】:

使用 php xlst 处理器解析以下内容会导致此错误:

`Warning: DOMDocument::load(): Namespace prefix g on id is not defined in /var/www    /mistermatic/spider/resources/xslt/car/google.xsl, line: 32 in /var/www/mistermatic/ads/PublicXML/makeXML.php on line 91`

如何正确定义 rss 节点内的命名空间,以便可以将其应用于我要操作的所有子节点?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="no" indent="yes"/>

    <xsl:template match="/">
        <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
            <channel>
        <title>Mistermatic</title>
        <link>http://www.mistermatic.it</link>
        <description>Multipubblicazione di annunci di automobili nuove ed usate</description>

                <xsl:for-each select="//ad">
                    <item xmlns:g="http://base.google.com/ns/1.0" version="2.0">
                        <xsl:apply-templates select="itemId"/>
                        <g:availability>in stock</g:availability>
                        <g:google_product_category><![CDATA[Veicoli a motore > Veicoli > Auto, autocarri e furgoni]]></g:google_product_category>
                    </item>
                </xsl:for-each>
            </channel>
        </rss>
    </xsl:template>

    <xsl:template match="itemId">
        <g:id>
            <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
            <xsl:value-of select="@value"/>
            <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
        </g:id>
    </xsl:template>

</xsl:stylesheet>

【问题讨论】:

    标签: xslt


    【解决方案1】:

    xmlns:g 声明上移到xsl:stylesheet 元素,使其在整个样式表中可见。

    【讨论】:

      【解决方案2】:

      问题是您在 rss 元素中定义命名空间,但是,它在 XSLT 文件的其他地方使用。尝试将命名空间定义移动到 XSLT 文档的根目录。

      【讨论】:

      • 好的,像这样在根目录中移动 xlmns 声明:&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://base.google.com/ns/1.0" version="2.0"&gt; 我是通过 php 得到的:警告:XSLTProcessor::importStylesheet():xsl:version:etc 等中仅支持 1.0 功能!!!我该怎么做才能在 2.0 版定义 google xmlns 并将 xsl xmlns 保持在 1.0 版?
      • version="2.0"留在rss元素上,只移动xmnls:g
      猜你喜欢
      • 1970-01-01
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多