Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 命名空间标识符不工作_Xml_Xslt_Namespaces - Fatal编程技术网

Xml 命名空间标识符不工作

Xml 命名空间标识符不工作,xml,xslt,namespaces,Xml,Xslt,Namespaces,下面是我将应用于基本xml文档的实践代码: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns="http://www.xml.com/books" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html>

下面是我将应用于基本xml文档的实践代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns="http://www.xml.com/books" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
     <html>
        <head>
            <title>XSLT</title>
            <style>
                h1, p {margin:0;}
            </style>
        </head>
     <body>
        <xsl:for-each select="/bookstore/book"> 
            <h1><xsl:value-of select="title"/></h1>
            <p>
                by
                <xsl:for-each select="author">
                    <xsl:value-of select="text()"/>
                </xsl:for-each>
                <xsl:text>, </xsl:text>

                <xsl:value-of select="year"/><br/>

                Price: £<xsl:value-of select="price"/><br/>

                <xsl:if test="photo">
                    <img style="height:200px;">
                        <xsl:attribute name="src">
                            <xsl:value-of select="photo"/>
                        </xsl:attribute>
                    </img>
                </xsl:if>
            </p>
        </xsl:for-each>
     </body>
     </html>
    </xsl:template>
</xsl:stylesheet>

XSLT
h1,p{margin:0;}

通过
, 

价格:£

  • 现在我被告知名称空间可以是任何东西。大多数情况下使用URL。那么,为什么当我尝试这段代码时,一切都会中断,格式化,等等。但是,当我将默认名称空间的标识符更改为“”时,它工作得非常好,如果xsl名称空间不是xsl/transform链接,则与xsl名称空间相同
  • 名称空间只是没有与我点击。我明白他们为什么在那里,他们的目的,但我不明白为什么像这样的事情是这样的

  • 另外,当您有两种类型的数据,xml和html时,名称空间如何知道哪些是html,哪些是xml以应用适当的格式

  • 非常感谢您的帮助

    您需要了解限定名称(简称QNames)的概念。XML中的许多实体,如元素和属性,都由QName标识,QName由名称空间和本地名称组成。例如,此元素:

    <foo:bar xmlns:foo="qwertyuiop">
    
    请注意,
    foo
    不是QName的一部分。像
    foo
    这样的名称空间前缀是一种简写,可以避免我们反复键入名称空间字符串。还要注意,名称空间字符串
    qwertyuiop
    是任意的。通常,按照约定,URI被用作名称空间标识符,但这只是因为希望这样可以防止冲突。如果我拥有
    jimrussell.us
    域,我对使用名为
    http://jimrussell.us/xsl/functions

    考虑一下:对于XML处理器(如果它工作正常),这三个XML文档是完全等效的:

    <foo:root xmlns:foo="urn:foo:space">
        <foo:child/>
    </foo:root>
    
    <xxx:root xmlns:xxx="urn:foo:space">
        <yyy:child xmlns:yyy="urn:foo:space"/>
    </xxx:root>
    
    <root xmlns="urn:foo:space">
        <child/>
    </root>
    
    
    

    在上一个示例中,我终于开始使用默认名称空间,其中没有前缀的所有内容都位于该名称空间中。

    与往常一样,Jeni说得最好。看,你的问题不是很清楚。如果您的结果应该是HTML,那么很自然,您不希望将输出元素放在任意的名称空间中(尽管许多浏览器会很高兴地忽略它)。我需要澄清的主要问题是,如果名称空间不是我提到的名称空间(都是w3链接),为什么名称空间会中断。当我读过的所有指南都说名称空间标识符可以是任何东西时,“我只是在这里胡思乱想。”好吧,当问题不具体时,回答起来有点困难“我读过的所有指南都说名称空间标识符可以是任何东西。”名称空间标识符不能是任何东西。它们必须符合您和您的接收者之前达成的协议(我想我们讨论的是输出中的名称空间)。如果您的目标应用程序希望事物位于名称空间X中,那么当它们位于名称空间Y中时,它将中断。您要求我重复我所说的。
    <foo:root xmlns:foo="urn:foo:space">
        <foo:child/>
    </foo:root>
    
    <xxx:root xmlns:xxx="urn:foo:space">
        <yyy:child xmlns:yyy="urn:foo:space"/>
    </xxx:root>
    
    <root xmlns="urn:foo:space">
        <child/>
    </root>