我有这个XML片段:
<svrl:active-pattern document="file:/D:/3.4Workspace/antSchematronTest/xml/CDA.xml"
id="p-2.16.840.1.113883.10.20.1.31-warning"
name="Result observation - warning validation phase"/>
<svrl:fired-rule context="*[cda:templateId/@root="2.16.840.1.113883.10.20.1.31"]"/>
<svrl:failed-assert test="cda:code[@codeSystem='2.16.840.1.113883.6.1' or @codeSystem='2.16.840.1.113883.6.96' ]"
location="/*[local-name()='ClinicalDocument']/*[local-name()='component']/*[local-name()='structuredBody']/*[local-name()='component'][4]/*[local-name()='section']/*[local-name()='entry'][1]/*[local-name()='organizer']/*[local-name()='component'][1]/*[local-name()='observation']">
<svrl:text>The value for "Observation / code" in a result observation SHOULD be selected from LOINC (codeSystem 2.16.840.1.113883.6.1) or SNOMED CT (codeSystem 2.16.840.1.113883.6.96).</svrl:text>
</svrl:failed-assert>
<svrl:failed-assert test="count(cda:effectiveTime)=1"
location="/*[local-name()='ClinicalDocument']/*[local-name()='component']/*[local-name()='structuredBody']/*[local-name()='component'][4]/*[local-name()='section']/*[local-name()='entry'][1]/*[local-name()='organizer']/*[local-name()='component'][1]/*[local-name()='observation']">
<svrl:text>A result observation SHOULD contain exactly one Observation / effectiveTime, which represents the biologically relevant time (e.g. time the specimen was obtained from the patient).</svrl:text>
</svrl:failed-assert>
<svrl:failed-assert test="cda:referenceRange"
location="/*[local-name()='ClinicalDocument']/*[local-name()='component']/*[local-name()='structuredBody']/*[local-name()='component'][4]/*[local-name()='section']/*[local-name()='entry'][1]/*[local-name()='organizer']/*[local-name()='component'][1]/*[local-name()='observation']">
<svrl:text>A result observation SHOULD contain one or more Observation / referenceRange to show the normal range of values for the observation result.</svrl:text>
</svrl:failed-assert>
<svrl:fired-rule context="*[cda:templateId/@root="2.16.840.1.113883.10.20.1.31"]"/>
<svrl:failed-assert test="cda:code[@codeSystem='2.16.840.1.113883.6.1' or @codeSystem='2.16.840.1.113883.6.96' ]"
location="/*[local-name()='ClinicalDocument']/*[local-name()='component']/*[local-name()='structuredBody']/*[local-name()='component'][4]/*[local-name()='section']/*[local-name()='entry'][1]/*[local-name()='organizer']/*[local-name()='component'][2]/*[local-name()='observation']">
<svrl:text>The value for "Observation / code" in a result observation SHOULD be selected from LOINC (codeSystem 2.16.840.1.113883.6.1) or SNOMED CT (codeSystem 2.16.840.1.113883.6.96).</svrl:text>
</svrl:failed-assert>
我正在将这个XSL模板应用于片段:
<xsl:template name="svrl:failed-assert" match="svrl:failed-assert">
<p><u>
<xsl:value-of select="(preceding-sibling::svrl:active-pattern)/@name[1]" />
</u></p>
<table width="800">
<tr>
<td colspan="2"><font color="red"><xsl:value-of select="svrl:text" />
</font></td>
</tr>
<tr>
<td width="50">Location:</td>
<td width="750">
<i>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="@location"/>
<xsl:with-param name="replace" select=""*[local-name()='""/>
<xsl:with-param name="by" select="''"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="replace" select=""']""/>
<xsl:with-param name="by" select="''"/>
</xsl:call-template>
</i></td>
</tr>
<tr>
<td width="50">Test:;</td>
<td width="750"><i><xsl:value-of select="@test" /></i></td>
</tr>
</table>
</xsl:template>
<xsl:template name="string-replace-all">
<xsl:param name="text" />
<xsl:param name="replace" />
<xsl:param name="by" />
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)" />
<xsl:value-of select="$by" />
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text"
select="substring-after($text,$replace)" />
<xsl:with-param name="replace" select="$replace" />
<xsl:with-param name="by" select="$by" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
这是输出:
Result observation - warning validation phase
The value for "Observation / code" in a result observation SHOULD be selected from LOINC (codeSystem 2.16.840.1.113883.6.1) or SNOMED CT (codeSystem 2.16.840.1.113883.6.96).
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[1]/observation
Test:; cda:code[@codeSystem='2.16.840.1.113883.6.1' or @codeSystem='2.16.840.1.113883.6.96' ]
Result observation - warning validation phase
A result observation SHOULD contain exactly one Observation / effectiveTime, which represents the biologically relevant time (e.g. time the specimen was obtained from the patient).
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[1]/observation
Test:; count(cda:effectiveTime)=1
Result observation - warning validation phase
A result observation SHOULD contain one or more Observation / referenceRange to show the normal range of values for the observation result.
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[1]/observation
Test:; cda:referenceRange
Result observation - warning validation phase
The value for "Observation / code" in a result observation SHOULD be selected from LOINC (codeSystem 2.16.840.1.113883.6.1) or SNOMED CT (codeSystem 2.16.840.1.113883.6.96).
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[2]/observation
Test:; cda:code[@codeSystem='2.16.840.1.113883.6.1' or @codeSystem='2.16.840.1.113883.6.96' ]
我希望svrl:active-pattern@name-“Result observation - warning validation phase”
只显示一次。例如:
Result observation - warning validation phase
The value for "Observation / code" in a result observation SHOULD be selected from LOINC (codeSystem 2.16.840.1.113883.6.1) or SNOMED CT (codeSystem 2.16.840.1.113883.6.96).
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[1]/observation
Test:; cda:code[@codeSystem='2.16.840.1.113883.6.1' or @codeSystem='2.16.840.1.113883.6.96' ]
A result observation SHOULD contain exactly one Observation / effectiveTime, which represents the biologically relevant time (e.g. time the specimen was obtained from the patient).
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[1]/observation
Test:; count(cda:effectiveTime)=1
A result observation SHOULD contain one or more Observation / referenceRange to show the normal range of values for the observation result.
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[1]/observation
Test:; cda:referenceRange
The value for "Observation / code" in a result observation SHOULD be selected from LOINC (codeSystem 2.16.840.1.113883.6.1) or SNOMED CT (codeSystem 2.16.840.1.113883.6.96).
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[2]/observation
Test:; cda:code[@codeSystem='2.16.840.1.113883.6.1' or @codeSystem='2.16.840.1.113883.6.96' ]
A result observation SHOULD contain one or more Observation / referenceRange to show the normal range of values for the observation result.
Location: /ClinicalDocument/component/structuredBody/component[4]/section/entry[1]/organizer/component[2]/observation
Test:; cda:referenceRange
我怎样才能做到这一点?
答案 0 :(得分:0)
看起来您只想输出您在XML中找到的第一个 svrl:failed-assert 元素的“结果观察 - 警告验证阶段”消息的段落,但不是任何其他人。
你需要做的是有一个模板来匹配第一个这样的元素,它可以输出第一个段落,然后调用命名模板 svrl:failed-assert ,它也将匹配所有其他元素也是。
<xsl:template match="svrl:failed-assert[1]">
<p>
<u>
<xsl:value-of select="(preceding-sibling::svrl:active-pattern)/@name[1]"/>
</u>
</p>
<xsl:call-template name="svrl:failed-assert"/>
</xsl:template>
<xsl:template match="svrl:failed-assert" name="svrl:failed-assert">
<!-- Existing code here -->
这是一个简化的XSLT(没有任何查找和替换代码)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svrl="oh:no" exclude-result-prefixes="svrl">
<xsl:output method="html" indent="yes"/>
<xsl:template match="svrl:failed-assert[1]">
<p>
<u>
<xsl:value-of select="(preceding-sibling::svrl:active-pattern)/@name[1]"/>
</u>
</p>
<xsl:call-template name="svrl:failed-assert"/>
</xsl:template>
<xsl:template match="svrl:failed-assert" name="svrl:failed-assert">
<table width="800">
<tr>
<td colspan="2">
<font color="red">
<xsl:value-of select="svrl:text"/>
</font>
</td>
</tr>
<tr>
<td width="50">Test:</td>
<td width="750">
<i>
<xsl:value-of select="@test"/>
</i>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
应用于以下简化的XML时:
<a xmlns:svrl="oh:no">
<svrl:active-pattern name="Result observation - warning validation phase"/>
<svrl:fired-rule context="Context 1"/>
<svrl:failed-assert test="Test 1" location="Location 1">
<svrl:text>Text 1</svrl:text>
</svrl:failed-assert>
<svrl:failed-assert test="Test 2" location="Location 2">
<svrl:text>Text 2</svrl:text>
</svrl:failed-assert>
<svrl:fired-rule context="Context 2"/>
<svrl:failed-assert test="Test 3" location="Location 3">
<svrl:text>Text 3</svrl:text>
</svrl:failed-assert>
</a>
输出以下HTML:
<p>
<u>Result observation - warning validation phase</u>
</p>
<table width="800">
<tr>
<td colspan="2">
<font color="red">Text 1</font>
</td>
</tr>
<tr>
<td width="50">Test:</td>
<td width="750">
<i>Test 1</i>
</td>
</tr>
</table>
<table width="800">
<tr>
<td colspan="2">
<font color="red">Text 2</font>
</td>
</tr>
<tr>
<td width="50">Test:</td>
<td width="750">
<i>Test 2</i>
</td>
</tr>
</table>
<table width="800">
<tr>
<td colspan="2">
<font color="red">Text 3</font>
</td>
</tr>
<tr>
<td width="50">Test:</td>
<td width="750">
<i>Test 3</i>
</td>
</tr>
</table>