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和XSL文件_Xml_Xslt - Fatal编程技术网

如何使用嵌入式XML和XSL文件

如何使用嵌入式XML和XSL文件,xml,xslt,Xml,Xslt,我正在尝试创建一个同时包含XML和XSL的嵌入式文件。该测试基于dpawson.co.uk。源代码如下所示: <?xml-stylesheet type="text/xml" href="#stylesheet"?> <!DOCTYPE doc [ <!ATTLIST xsl:stylesheet id ID #REQUIRED> ]> <doc> <xsl:stylesheet id="stylesheet"

我正在尝试创建一个同时包含XML和XSL的嵌入式文件。该测试基于dpawson.co.uk。源代码如下所示:

<?xml-stylesheet type="text/xml" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
  id    ID  #REQUIRED>
]>
<doc>
<xsl:stylesheet id="stylesheet"
                version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- any xsl:import elements -->
  <xsl:template match="xsl:stylesheet" />
  <!-- rest of your stylesheet -->
</xsl:stylesheet>

<!-- rest of your XML document -->
</doc>
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<Report>
    <ReportFor>Test Data</ReportFor>
    <CreationTime>2009-07-29 05:37:14</CreationTime>
</Report>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <!-- ... -->
    <xsl:value-of select="Report/ReportFor" />
    <!-- ... -->
    <xsl:value-of select="Report/CreationTime"/>
    <!-- ... -->
  </xsl:template>
</xsl:stylesheet>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
  id    ID  #REQUIRED>
]>
<doc>
<xsl:stylesheet id="stylesheet"
                version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- any xsl:import elements -->
  <xsl:template match="xsl:stylesheet" />
  <!-- rest of your stylesheet -->
  <xsl:template match="/">
    <!-- ... -->
    <xsl:value-of select="Report/ReportFor" />
    <!-- ... -->
    <xsl:value-of select="Report/CreationTime"/>
    <!-- ... -->
  </xsl:template>
</xsl:stylesheet>

<!-- rest of your XML document -->
<Report>
    <ReportFor>Test Data</ReportFor>
    <CreationTime>2009-07-29 05:37:14</CreationTime>
</Report>

</doc>
基于这些,我试图创建一个同时包含XML和XSL的嵌入式XML文件

当前,此文件如下所示:

<?xml-stylesheet type="text/xml" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
  id    ID  #REQUIRED>
]>
<doc>
<xsl:stylesheet id="stylesheet"
                version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- any xsl:import elements -->
  <xsl:template match="xsl:stylesheet" />
  <!-- rest of your stylesheet -->
</xsl:stylesheet>

<!-- rest of your XML document -->
</doc>
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<Report>
    <ReportFor>Test Data</ReportFor>
    <CreationTime>2009-07-29 05:37:14</CreationTime>
</Report>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <!-- ... -->
    <xsl:value-of select="Report/ReportFor" />
    <!-- ... -->
    <xsl:value-of select="Report/CreationTime"/>
    <!-- ... -->
  </xsl:template>
</xsl:stylesheet>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
  id    ID  #REQUIRED>
]>
<doc>
<xsl:stylesheet id="stylesheet"
                version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- any xsl:import elements -->
  <xsl:template match="xsl:stylesheet" />
  <!-- rest of your stylesheet -->
  <xsl:template match="/">
    <!-- ... -->
    <xsl:value-of select="Report/ReportFor" />
    <!-- ... -->
    <xsl:value-of select="Report/CreationTime"/>
    <!-- ... -->
  </xsl:template>
</xsl:stylesheet>

<!-- rest of your XML document -->
<Report>
    <ReportFor>Test Data</ReportFor>
    <CreationTime>2009-07-29 05:37:14</CreationTime>
</Report>

</doc>

测试数据
2009-07-29 05:37:14
此文档的问题在于
无法检索XML部分中表示的数据。
如何识别嵌入的数据?是否需要一些特殊语法?

是否需要使用“.”运算符来获取值

 <xsl:value-of select="Report/ReportFor/."/>

模板匹配属性中缺少doc元素。请尝试以下方法:

<xsl:template match="/doc">
   <xsl:value-of select="Report/ReportFor" />
</xsl:template>

See我正要发布“在XSL中嵌入XML”的建议,但既然已经得到了回答:链接更好。