Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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_Xslt 1.0 - Fatal编程技术网

Xml 为什么此代码没有';不输出任何XSLT

Xml 为什么此代码没有';不输出任何XSLT,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我对XSLT一无所知。所以我试着做一个例子,输出一个元素的值。输出格式为纯文本格式。 这是名为cdcatalog.XML的XML文件: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="catalog.xsl"?> <catalog> <cd> <title>Empire</title>

我对XSLT一无所知。所以我试着做一个例子,输出一个元素的值。输出格式为纯文本格式。 这是名为cdcatalog.XML的XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="catalog.xsl"?>
<catalog>
    <cd>
        <title>Empire</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>
            <europe_country>Bulgaria</europe_country>
            <azia_coutry>China</azia_coutry>
        </country>
        <company>CBS Records</company>
        <price>9.90</price>
        <year>1988</year>
    </cd>
</catalog>
但输出窗口中没有显示任何内容。 我错在哪里? 提前谢谢。

  • 您需要
    遍历
    目录中的
    cd
    元素。记住这一点
  • 您说xsl文件名为
    cdcatalog.xsl
    ,但xml中的
    href
    catalog.xsl
      • 您需要
        遍历
        目录中的
        cd
        元素。记住这一点
      • 您说xsl文件名为
        cdcatalog.xsl
        ,但xml中的
        href
        catalog.xsl
          • 您需要
            遍历
            目录中的
            cd
            元素。记住这一点
          • 您说xsl文件名为
            cdcatalog.xsl
            ,但xml中的
            href
            catalog.xsl
              • 您需要
                遍历
                目录中的
                cd
                元素。记住这一点
              • 您说xsl文件名为
                cdcatalog.xsl
                ,但xml中的
                href
                catalog.xsl

              编写模板时,尝试直接针对(即匹配)您感兴趣的内容(在本例中为
              标题
              元素)

              XSLT样式表

              Empire
              Hide your heart
              
              如您所见,还有第二个模板与
              text()
              匹配。如果省略它,则输入文档中的所有文本内容都将被输出,因为这是XSLT处理器对文本节点的默认行为

              <?xml version="1.0" encoding="UTF-8" ?>
              <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
                  <xsl:output method="text" encoding="UTF-8" />
              
                  <xsl:template match="title">
                    <xsl:value-of select="."/>
                    <xsl:text>&#10;</xsl:text>
                  </xsl:template>
              
                  <xsl:template match="text()"/>
              
              </xsl:transform>
              

              在线尝试此解决方案



              顺便说一句,确保元素的名称一致。名为
              azia\u coutry
              的元素与
              asia\u coutry
              asia\u country
              完全不同。编写模板时,请尝试直接针对(即匹配)您感兴趣的内容(在本例中为
              title
              元素)

              XSLT样式表

              Empire
              Hide your heart
              
              如您所见,还有第二个模板与
              text()
              匹配。如果省略它,则输入文档中的所有文本内容都将被输出,因为这是XSLT处理器对文本节点的默认行为

              <?xml version="1.0" encoding="UTF-8" ?>
              <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
                  <xsl:output method="text" encoding="UTF-8" />
              
                  <xsl:template match="title">
                    <xsl:value-of select="."/>
                    <xsl:text>&#10;</xsl:text>
                  </xsl:template>
              
                  <xsl:template match="text()"/>
              
              </xsl:transform>
              

              在线尝试此解决方案



              顺便说一句,确保元素的名称一致。名为
              azia\u coutry
              的元素与
              asia\u coutry
              asia\u country
              完全不同。编写模板时,请尝试直接针对(即匹配)您感兴趣的内容(在本例中为
              title
              元素)

              XSLT样式表

              Empire
              Hide your heart
              
              如您所见,还有第二个模板与
              text()
              匹配。如果省略它,则输入文档中的所有文本内容都将被输出,因为这是XSLT处理器对文本节点的默认行为

              <?xml version="1.0" encoding="UTF-8" ?>
              <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
                  <xsl:output method="text" encoding="UTF-8" />
              
                  <xsl:template match="title">
                    <xsl:value-of select="."/>
                    <xsl:text>&#10;</xsl:text>
                  </xsl:template>
              
                  <xsl:template match="text()"/>
              
              </xsl:transform>
              

              在线尝试此解决方案



              顺便说一句,确保元素的名称一致。名为
              azia\u coutry
              的元素与
              asia\u coutry
              asia\u country
              完全不同。编写模板时,请尝试直接针对(即匹配)您感兴趣的内容(在本例中为
              title
              元素)

              XSLT样式表

              Empire
              Hide your heart
              
              如您所见,还有第二个模板与
              text()
              匹配。如果省略它,则输入文档中的所有文本内容都将被输出,因为这是XSLT处理器对文本节点的默认行为

              <?xml version="1.0" encoding="UTF-8" ?>
              <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
                  <xsl:output method="text" encoding="UTF-8" />
              
                  <xsl:template match="title">
                    <xsl:value-of select="."/>
                    <xsl:text>&#10;</xsl:text>
                  </xsl:template>
              
                  <xsl:template match="text()"/>
              
              </xsl:transform>
              

              在线尝试此解决方案


              顺便说一句,确保元素的名称一致。一个名为
              azia\u coutry
              的元素与
              asia\u coutry
              asia\u country
              完全不同