【发布时间】:2013-10-04 17:01:35
【问题描述】:
我有以下 xml 文件:
<section>
<templateId root="2.16.840.1.113883.10.20.22.2.4" />
<text>
<list listType="ordered">
<item>9/18/2013 - Weight - 125 lbs</item>
<item>9/18/2013 - Blood Pressure - 120/80 mm Hg</item>
<item>9/18/2013 - BMI - 19 98</item>
<item>9/11/2013 - Weight - 125 lbs</item>
<item>9/11/2013 - Blood Pressure - 120/80 mm Hg</item>
<item>9/11/2013 - BMI - 19 98</item>
<item>9/11/2013 - Pulse - 32</item>
</list>
</text>
</section>
我有以下xsl模板信息:
<xsl:key name="vs_times" match="//hl7:section[hl7:templateId/@root='2.16.840.1.113883.10.20.22.2.4']/hl7:text/hl7:list/hl7:item" use="substring-before(., ' - ')"/>
<xsl:template match="hl7:section[hl7:templateId/@root='2.16.840.1.113883.10.20.22.2.4']">
<div style="padding: 5px; border-top: 1px solid #000000;">
<span style="font-weight: bold;">Vital Signs: </span>
<br/>
<table border="0" cellspacing="0" cellpadding="1" width="100%">
<xsl:apply-templates select="hl7:text/hl7:list/hl7:item[generate-id(.)=generate-id(key('vs_times', substring-before(., ' - ')))]" mode="group" />
</table>
</div>
</xsl:template>
<xsl:template match="hl7:item" mode="group">
<tr>
<td style="width: 76px;">
<xsl:value-of select="substring-before(., ' - ')" />
</td>
<xsl:variable name="values" select="key('vs_times', substring-before(., ' - '))"/>
<xsl:apply-templates select="$values" />
</tr>
</xsl:template>
<xsl:template match="hl7:item">
<td style="width: 180px; padding-left: 3px;">
<xsl:apply-templates select="." mode="content" />
</td>
</xsl:template>
<xsl:template match="hl7:item[contains(., 'Blood Pressure')]" mode="content">
<span style="font-weight: bold;">Blood Pressure: </span>
<xsl:value-of select="substring-before(substring-after(., 'Blood Pressure - '), ' ')"/>
</xsl:template>
<xsl:template match="hl7:item[contains(., 'Pulse')]" mode="content">
<span style="font-weight: bold;">Pulse: </span>
<xsl:value-of select="substring-before(substring-after(., 'Pulse - '), ' ')"/>
</xsl:template>
<xsl:template match="hl7:item[contains(., 'Weight')]" mode="content">
<span style="font-weight: bold;">Weight: </span>
<xsl:value-of select="substring-after(., 'Weight - ')"/>
</xsl:template>
<xsl:template match="hl7:item[contains(., 'BMI')]" mode="content">
<span style="font-weight: bold;">BMI: </span>
<xsl:value-of select="substring-before(substring-after(., 'BMI - '), ' ')"/>
</xsl:template>
<xsl:template match="hl7:item" mode="content">
 
</xsl:template>
这会输出信息,但我需要输出的顺序(可能)与被迭代的项目不同。我需要它们始终保持相同的顺序:
- 血压
- 脉冲
- 重量
- 体重指数
到目前为止,它只是循环遍历每个项目并在涉及到它们时输出它们。
此外,如果四个项目中没有一个(因为示例中的第一组日期中没有脉冲项目),则需要有一个空格。最后,第二行必须是与第一行不同的颜色。
谢谢
【问题讨论】:
-
@Viji 不是重复的.. 扩展名......另一个问题确实有效并得到了回答,但现在我需要进一步的帮助才能让项目以特定的顺序显示(而不仅仅是让它们显示出来)。
标签: xml xslt xslt-1.0 xslt-grouping