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

6 xml xslt

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

<?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>
Run Code Online (Sandbox Code Playgroud)

最初我已经制作了一个有效的XML和XSL文件.XML看起来像这样:

<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<Report>
    <ReportFor>Test Data</ReportFor>
    <CreationTime>2009-07-29 05:37:14</CreationTime>
</Report>
Run Code Online (Sandbox Code Playgroud)

data.xsl文件看起来像这样:

<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>
Run Code Online (Sandbox Code Playgroud)

基于这些,我正在尝试创建一个包含XML和XSL的嵌入式XML文件.

目前这个文件看起来像这样:

<?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>
Run Code Online (Sandbox Code Playgroud)

本文档的问题在于<xsl:value-of>它不检索XML部分中表示的数据.如何<xsl:value-of>识别嵌入数据?是否需要一些特殊的语法?

Ste*_*ven 0

这个需要用“.”吗 运算符来获取值?

 <xsl:value-of select="Report/ReportFor/."/>
Run Code Online (Sandbox Code Playgroud)