Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 XSLT转换无法解决如何包含名称空间的问题?_Xml_Xslt - Fatal编程技术网

Xml XSLT转换无法解决如何包含名称空间的问题?

Xml XSLT转换无法解决如何包含名称空间的问题?,xml,xslt,Xml,Xslt,我正在尝试创建一个XSLT文件,我可以让它工作,而不必在任何一个文件中包含名称空间,但一旦我在其中包含名称空间,它就会停止工作。 下面是我正在使用的示例 <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia<

我正在尝试创建一个XSLT文件,我可以让它工作,而不必在任何一个文件中包含名称空间,但一旦我在其中包含名称空间,它就会停止工作。 下面是我正在使用的示例

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>
我的XML文件

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>

皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
帝国自卫队
鲍勃·sdf
2.
asdfs
12.90
1935
我的转换文件

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
  <html><body><table border="1">
    <tr bgcolor="#9acd32"><th>Title</th><th>Artist</th></tr>
    <xsl:for-each select="catalog/cd">
    <tr>   
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="artist"/></td>
    </tr>
    </xsl:for-each>
  </table></body></html>
</xsl:template>

</xsl:stylesheet>
       <?xml version="1.0" encoding="ISO-8859-1"?>

        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.someurl.com/v3.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.someurl.com/v3.0 ../someschema.xsl">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
          <html><body><table border="1">
            <tr bgcolor="#9acd32"><th>Title</th><th>Artist</th></tr>
            <xsl:for-each select="catalog/cd">
            <tr>   
              <td><xsl:value-of select="title"/></td>
              <td><xsl:value-of select="artist"/></td>
            </tr>
            </xsl:for-each>
          </table></body></html>
        </xsl:template>

        </xsl:stylesheet>

标题学家
我的结果

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>
<?xml version="1.0" encoding="UTF-8"?>
<html>
    <body>
        <table border="1">
            <tr bgcolor="#9acd32">
                <th>Title</th>
                <th>Artist</th>
            </tr>
            <tr>
                <td>Empire Burlesque</td>
                <td>Bob Dylan</td>
            </tr>
            <tr>
                <td>Empire sdf</td>
                <td>Bob sdf</td>
            </tr>
        </table>
    </body>
</html>

标题
艺术家
皇帝讽刺剧
鲍勃·迪伦
帝国自卫队
鲍勃·sdf
如果我将上述内容更改为此,则不会。 我的新XML文件

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog
xmlns="http://www.someurl.com/v3.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.someurl.com/v3.0 ../someschema.xsl"
>

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>

皇帝讽刺剧
鲍勃·迪伦
美国
哥伦比亚
10.90
1985
帝国自卫队
鲍勃·sdf
2.
asdfs
12.90
1935
我的新转换文件

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
  <html><body><table border="1">
    <tr bgcolor="#9acd32"><th>Title</th><th>Artist</th></tr>
    <xsl:for-each select="catalog/cd">
    <tr>   
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="artist"/></td>
    </tr>
    </xsl:for-each>
  </table></body></html>
</xsl:template>

</xsl:stylesheet>
       <?xml version="1.0" encoding="ISO-8859-1"?>

        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.someurl.com/v3.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.someurl.com/v3.0 ../someschema.xsl">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
          <html><body><table border="1">
            <tr bgcolor="#9acd32"><th>Title</th><th>Artist</th></tr>
            <xsl:for-each select="catalog/cd">
            <tr>   
              <td><xsl:value-of select="title"/></td>
              <td><xsl:value-of select="artist"/></td>
            </tr>
            </xsl:for-each>
          </table></body></html>
        </xsl:template>

        </xsl:stylesheet>

标题学家
我现在转换的文件中没有数据了?
如果这个问题是基本问题,请原谅,我没有XSLT方面的经验,目前我正在努力解决这个问题。

在XSLT2.0中:您只需在
xsl:stylesheet
元素中添加以下属性:
xpath default namespace=”http://www.someurl.com/v3.0“

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>
使用XSLT1.0:您必须通过提供前缀来限定xsl文件中的名称空间。示例如下:

  <cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
  </cd>
  <cd>
    <title>Empire sdf</title>
    <artist>Bob sdf</artist>
    <country>2</country>
    <company>asdfs</company>
    <price>12.90</price>
    <year>1935</year>
  </cd>
</catalog>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ns="http://www.someurl.com/v3.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.someurl.com/v3.0 ../someschema.xsl">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
        <html><body><table border="1">
            <tr bgcolor="#9acd32"><th>Title</th><th>Artist</th></tr>
            <xsl:for-each select="ns:catalog/ns:cd">
                <tr>   
                    <td><xsl:value-of select="ns:title"/></td>
                    <td><xsl:value-of select="ns:artist"/></td>
                </tr>
            </xsl:for-each>
        </table></body></html>
    </xsl:template>

</xsl:stylesheet>

标题学家

我将其添加到xslt文件中,但现在在对其运行时获得了一个意外属性?将它添加到我的xml文件中没有什么区别吗?是的,我纠正了它:xpath默认名称空间只是XSLT2.0的一个特性。对不起,我能感觉到钱快用完了:)谢谢你的帮助。