Xslt xsl 1.0为什么节点不匹配返回数据

Xslt xsl 1.0为什么节点不匹配返回数据,xslt,xslt-1.0,Xslt,Xslt 1.0,我正在使用以下xml信息: <section> <...> </section> <section> <templateId root="2.16.840.1.113883.10.20.22.2.10" /> <text> <table id="Appointments"> <tr> <td id="heading">Appointments

我正在使用以下xml信息:

<section>
  <...>
</section>
<section>
  <templateId root="2.16.840.1.113883.10.20.22.2.10" />
  <text>
    <table id="Appointments">
      <tr>
        <td id="heading">Appointments</td>
      </tr>
      <tr>
        <td id="content">No future appointments scheduled.</td>
      </tr>
    </table>
    <br />
    <table id="Referrals">
      <tr>
        <td id="heading">Referrals</td>
      </tr>
      <tr>
        <td id="content">No referrals available.</td>
      </tr>
    </table>
    <br />
  </text>
<section>
<section>
  <...>
</section>
有多个节节点及其自己的子节点,包括文档中的templateId。我在这方面遇到了一些问题,所以我想在xml信息中明确一些

在我的xslt文件中,我想得到一个特定的表。我以下面的方式引用它,我尝试使用模板,而且我对XSL是新手,所以请耐心听我说

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns="http://www.w3.org/1999/xhtml">


<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
  <xsl:apply-templates select="//section[templateId/@root='2.16.840.1.113883.10.20.22.2.17']/text/table[@id='Appointments']" />
</xsl: template>

<xsl:template match="section[templateId/@root='2.16.840.1.113883.10.20.22.2.17']/text/table[@id='Appointments']">
  <div style="float: left; width: 50%;">
    <span style="font-weight: bold;">
    <xsl:value-of select="tr/td[@id='heading']"/>:
    </span>
    <br />
    <xsl:call-template name="replace">
      <xsl:with-param name="string" select="tr/td[@id='content']"/>
    </xsl:call-template>
    </div>
</xsl:template>

<xsl:template name="replace">
  <xsl:param name="string"/>
  <xsl:choose>
    <xsl:when test="contains($string,'&#10;')">
      <xsl:value-of select="substring-before($string,'&#10;')"/>
      <br/>
      <xsl:call-template name="replace">
        <xsl:with-param name="string" select="substring-after($string,'&#10;')"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$string"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>
在这个特定的xml示例中,输出应该是:

任命: 没有安排未来的约会

我认为比赛和选择需要一些调整,但不确定是什么部分

此外,如果可以调整模板,以便我可以传递一个带有table/@id值的参数,以便我可以将这一模板用于几个项目,那么这将更加有益。本例中的推荐和约会输出将是相同的


感谢您的帮助

这是从XML中剪切并粘贴的XML节根属性:

 root="2.16.840.1.113883.10.20.22.2.10" 
这是您的测试XSL:

 root='2.16.840.1.113883.10.20.22.2.17'
当然他们不匹配,一个以10结尾,另一个以17结尾

将数据更改为17并更正我评论中的其他错误会产生:

 <div style="float: left; width: 50%;"><span style="font-weight: bold;">Appointments:
       </span><br>No future appointments scheduled.
 </div

您的真实文档是否声明了任何名称空间,特别是它是否具有默认名称空间xmlns=。。。在树的更高位置?@Ian Roberts-更新了xslt示例以包含标题信息。我不是指xslt,而是指包含元素的输入XML文档。对此表示抱歉。不,xml文档中没有这些元素。注意:上面示例中的section元素已损坏/不正确,因此如果看不到正确的xml,很难说。。。开始一个新的部分,而不是结束该部分。该模板中的XSL中也有一个错误。。。它以:注意空格结束。如果这些是真实的源代码,那么不应该运行任何东西,XSLT处理器应该抛出一个errorOh。我的上帝非常感谢。我甚至没有注意到。我是从别的东西上复制粘贴的,甚至没有改变它。