我正在尝试在 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>
这只是 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>
这给了我正确的行数,但是在返回的第一行之后 @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>
如图所示,每对都有日期,但该值对应于第一个 @id='testdate' 并且不排序。无法弄清楚我做错了什么,以便他们通过。同样,我希望我可以按原样显示表格,但我不能获得我需要的输出。
提前感谢您的任何帮助。