Xml XSLT 1.0-获取两个单独的节点/@值以显示在表中

Xml XSLT 1.0-获取两个单独的节点/@值以显示在表中,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我试图在xml节点中获得两个不同的id值,以表格式显示。xml如下所示: <root> <section> <templateId root="2.16.840.1.113883.10.20.22.2.10" /> <text> <table id="ScheduledTests"> <tr> <td id="heading">Scheduled Tests</t

我试图在xml节点中获得两个不同的id值,以表格式显示。xml如下所示:

<root>
<section>
  <templateId root="2.16.840.1.113883.10.20.22.2.10" />
  <text>
    <table id="ScheduledTests">
      <tr>
        <td id="heading">Scheduled Tests</td>
        <td>Order Date</td>
      </tr>
      <tr>
        <td id="content">Lab for JJ</td>
        <td id="testdate">9/20/2013 12:00:00 AM</td>
      </tr>
      <tr>
        <td id="content">Rad for JJ</td>
        <td id="testdate">9/20/2013 12:00:00 AM</td>
      </tr>
      <tr>
        <td id="content">Lab for JJ</td>
        <td id="testdate">9/11/2013 12:00:00 AM</td>
      </tr>
      <tr>
        <td id="content">Rad for JJ</td>
        <td id="testdate">9/11/2013 12:00:00 AM</td>
      </tr>
      <tr>
        <td id="content">Referral for JJ</td>
        <td id="testdate">9/11/2013 12:00:00 AM</td>
      </tr>
      <tr>
        <td id="content">Lab for JJ</td>
        <td id="testdate">9/6/2013 12:00:00 AM</td>
      </tr>
      <tr>
        <td id="content">Rad for JJ</td>
        <td id="testdate">9/6/2013 12:00:00 AM</td>
      </tr>
    </table>
  </text>
</section>
<section>
  <...>
</section>
<section>
  <...>
</section>
</root>

计划测试
订购日期
JJ实验室
2013年9月20日上午12:00:00
JJ的Rad
2013年9月20日上午12:00:00
JJ实验室
2013年11月9日上午12:00:00
JJ的Rad
2013年11月9日上午12:00:00
转介给JJ
2013年11月9日上午12:00:00
JJ实验室
2013年9月6日上午12:00:00
JJ的Rad
2013年9月6日上午12:00:00
这只是xml片段。根下还有其他块,因此不是实际的根节点

它是以表格的形式设置的,但不幸的是,我不能直接读入并处理它。我的xslt中包含以下内容:

<xsl:template match="/">
  <!-- Scheduled Tests -->
  <xsl:apply-templates select="//section[templateId/@root='2.16.840.1.113883.10.20.22.2.10']/text/table[@id='ScheduledTests']"/>
</xsl:template>

<!-- template for scheduled tests -->
<xsl:template match="section[templateId/@root='2.16.840.1.113883.10.20.22.2.10']/text/table[@id='ScheduledTests']">
  <div style="padding: 5px; border-top: 1px solid #000000;">
    <span style="font-weight: bold;">
      <xsl:value-of select="tr/td[@id='heading']"/>:
    </span>
    <br />
    <xsl:for-each select="tr/td[@id='content']">
            <div>
                <xsl:choose>
                    <xsl:when test="position() mod 2 = 0">
                        <xsl:attribute name="style">
                            <xsl:text>padding: 2px 0px 2px 0px; background-color: #dcdcdc;</xsl:text>
                        </xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="style">
                            <xsl:text>padding: 2px 0px 2px 0px;</xsl:text>
                        </xsl:attribute>
                    </xsl:otherwise>
                </xsl:choose>
                <table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <tr>
                        <td style="font-size: 11px;  text-align: left;"><xsl:value-of select="."/></td>
                        <td style="font-size: 11px;  text-align: right;"><xsl:value-of select="substring-before(../../tr/td[@id='testdate'], ' ')"/></td>
                    </tr>
                </table>
            </div>
    </xsl:for-each>
  </div>
</xsl:template>

:

填充:2px0px 2px0px;背景色:#DCDC; 填充:2px0px 2px0px;
这给了我正确的行数,但返回的第一行后面的@id='testdate'不正确:

<div style="padding: 5px; border-top: 1px solid #000000;" xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns="http://www.w3.org/1999/xhtml">
  <span style="font-weight: bold;">Scheduled Tests:</span><br />
  <div style="padding: 2px 0px 2px 0px;">
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr><td style="font-size: 11px;  text-align: left;">Lab for JJ</td>
      <td style="font-size: 11px;  text-align: right;">9/20/2013</td></tr>
    </table>
  </div>
  <div style="padding: 2px 0px 2px 0px; background-color: #dcdcdc;">
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr><td style="font-size: 11px;  text-align: left;">Rad for JJ</td>
      <td style="font-size: 11px;  text-align: right;">9/20/2013</td></tr>
    </table>
  </div>
  <div style="padding: 2px 0px 2px 0px;">
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr><td style="font-size: 11px;  text-align: left;">Lab for JJ</td>
      <td style="font-size: 11px;  text-align: right;">9/20/2013</td></tr>
    </table>
  </div>
  <div style="padding: 2px 0px 2px 0px; background-color: #dcdcdc;">
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr><td style="font-size: 11px;  text-align: left;">Rad for JJ</td>
      <td style="font-size: 11px;  text-align: right;">9/20/2013</td></tr>
    </table>
  </div>
  <div style="padding: 2px 0px 2px 0px;">
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr><td style="font-size: 11px;  text-align: left;">Referral for JJ</td>
      <td style="font-size: 11px;  text-align: right;">9/20/2013</td></tr>
    </table>
  </div>
  <div style="padding: 2px 0px 2px 0px; background-color: #dcdcdc;">
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr><td style="font-size: 11px;  text-align: left;">Lab for JJ</td>
      <td style="font-size: 11px;  text-align: right;">9/20/2013</td></tr>
    </table>
  </div>
  <div style="padding: 2px 0px 2px 0px;">
    <table border="0" cellspacing="0" cellpadding="0" width="100%">
      <tr><td style="font-size: 11px;  text-align: left;">Rad for JJ</td>
      <td style="font-size: 11px;  text-align: right;">9/20/2013</td></tr>
    </table>
  </div>
</div>

计划测试:
JJ实验室 9/20/2013 JJ的Rad 9/20/2013 JJ实验室 9/20/2013 JJ的Rad 9/20/2013 转介给JJ 9/20/2013 JJ实验室 9/20/2013 JJ的Rad 9/20/2013
如图所示,每对都有日期,但该值对应于第一个@id='testdate',不按顺序排列。我不知道我做错了什么,所以他们会通过。同样,我希望我能按原样显示表格,但我不能为我需要的输出提供支持


提前感谢您的帮助。

我知道我需要做什么了。以下一行:

<td style="font-size: 11px;  text-align: right;">
  <xsl:value-of select="substring-before(../../tr/td[@id='testdate'], ' ')"/>
</td>

我需要换成:

<td style="font-size: 11px;  text-align: right;">
  <xsl:value-of select="substring-before(../td[@id='testdate'], ' ')"/>
</td>


我退得太远了,又回来了。我只需要回到tr标签上,获得带有@id=testdate的td,为您自己的问题提供答案,这样其他人就不会感到疑惑了。