我使用以下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,' ')">
<xsl:value-of select="substring-before($string,' ')"/>
<br/>
<xsl:call-template name="replace">
<xsl:with-param name="string" select="substring-after($string,' ')"/>
</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