为xsl:key

时间:2017-03-03 00:40:35

标签: xslt xpath

使用XSLT 1.0,是否可以基于两个“相关”xml元素创建xsl:key?

例如,我想创建一个连接以下值的键:

  1. /component/section/text/table/tbody/tr/td[1]/text()
  2. /component/section/entry/act/effectiveTime/low/@value
  3. 理想情况下,密钥会看起来像:

    1. test description|20161229000000
    2. test description2|20161230000000
    3. 这些元素在某种意义上是相关的,它们共享一个具有相同引用标识(ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_name_*)的兄弟元素作为属性。

      定义键时,需要指定“匹配”xpath模式和“使用”xpath模式。但是,创建一个可以解释具有特定值的相关属性的模式似乎很困难,尤其是当元素具有不同的父元素且相关属性值对于每对相关元素不同时。

      示例xml:

      <?xml version="1.0" ?>
        <component>
          <section classCode="DOCSECT" moodCode="EVN">
              <text mediaType="text/x-hl7-text+xml">
                  <table border="1">
                      <tbody>
                          <tr>
                              <td ID="ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_name_1">test description</td>
                              <td ID="ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_dateOfOnset_1">12/29/2016</td>
                              <td ID="ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_comments_1"/>
                          </tr>
                          <tr>
                              <td ID="ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_name_2">test description2</td>
                              <td ID="ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_dateOfOnset_2">12/30/2016</td>
                              <td ID="ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_comments_2"/>
                          </tr>
                      </tbody>
                  </table>
              </text>
              <entry>
                  <act classCode="ACT" moodCode="EVN">
                      <id extension="1206ca2c614d4d07990b0162ee99aaf1" root="2.16.840.1.113883.3.441"/>
                      <code nullFlavor="NA"/>
                      <statusCode code="completed"/>
                      <effectiveTime>
                          <low value="20161229000000"/>
                          <high nullFlavor="UNK"/>
                      </effectiveTime>
                      <entryRelationship inversionInd="false" typeCode="SUBJ">
                          <observation classCode="OBS" moodCode="EVN" negationInd="false">
                              <templateId root="2.16.840.1.113883.10.20.1.28"/>
                              <id extension="99999999" root="2.16.840.1.113883.3.441.1.50.869.51.1349970.61"/>
                              <code code="55607006"
                                  codeSystem="2.16.840.1.113883.6.96"
                                  codeSystemName="SNOMED CT" displayName="undescriptive display name"/>
                              <text>
                                  <reference value="#ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_name_1"/>
                              </text>
                              <statusCode code="completed"/>
                              <effectiveTime>
                                  <low value="20161229000000"/>
                              </effectiveTime>
                              <value code="783.3" codeSystemName="ICD9" displayName="undescriptive display name">
                                  <originalText>ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_name_1</originalText>
                              </value>
                              <entryRelationship inversionInd="false" typeCode="REFR">
                                  <observation classCode="OBS" moodCode="EVN">
                                      <templateId root="2.16.840.1.113883.10.20.1.50"/>
                                      <code code="33999-4"
                                          codeSystem="2.16.840.1.113883.6.1"
                                          codeSystemName="LOINC" displayName="Status"/>
                                      <statusCode code="Completed"/>
                                      <value code="73425007"
                                          codeSystem="2.16.840.1.113883.6.96"
                                          codeSystemName="SNOMED CT" displayName="InActive"/>
                                  </observation>
                              </entryRelationship>
                          </observation>
                      </entryRelationship>
                  </act>
              </entry>
              <entry>
                  <act classCode="ACT" moodCode="EVN">
                      <id extension="1206ca2c614d4d07990b0162ee99aaf1" root="2.16.840.1.113883.3.441"/>
                      <code nullFlavor="NA"/>
                      <statusCode code="completed"/>
                      <effectiveTime>
                          <low value="20161230000000"/>
                          <high nullFlavor="UNK"/>
                      </effectiveTime>
                      <entryRelationship inversionInd="false" typeCode="SUBJ">
                          <observation classCode="OBS" moodCode="EVN" negationInd="false">
                              <templateId root="2.16.840.1.113883.10.20.1.28"/>
                              <id extension="99999999" root="2.16.840.1.113883.3.441.1.50.869.51.1349970.61"/>
                              <code code="55607006"
                                  codeSystem="2.16.840.1.113883.6.96"
                                  codeSystemName="SNOMED CT" displayName="undescriptive display name2"/>
                              <text>
                                  <reference value="#ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_name_2"/>
                              </text>
                              <statusCode code="completed"/>
                              <effectiveTime>
                                  <low value="20161230000000"/>
                              </effectiveTime>
                              <value code="783.3" codeSystemName="ICD9" displayName="undescriptive display name2">
                                  <originalText>ref_b71a6ee05ef245f1a0c3f302ca769077_pastIllness_name_2</originalText>
                              </value>
                              <entryRelationship inversionInd="false" typeCode="REFR">
                                  <observation classCode="OBS" moodCode="EVN">
                                      <templateId root="2.16.840.1.113883.10.20.1.50"/>
                                      <code code="33999-4"
                                          codeSystem="2.16.840.1.113883.6.1"
                                          codeSystemName="LOINC" displayName="Status"/>
                                      <statusCode code="Completed"/>
                                      <value code="73425007"
                                          codeSystem="2.16.840.1.113883.6.96"
                                          codeSystemName="SNOMED CT" displayName="InActive"/>
                                  </observation>
                              </entryRelationship>
                          </observation>
                      </entryRelationship>
                  </act>
              </entry>
          </section> </component>
      

1 个答案:

答案 0 :(得分:0)

在基于共享属性/元素值连接两个元素时,current()函数非常有用。

这是原始问题中xml的键的示例:

<xsl:key name="testKey" match="/component/section/text/table/tbody/tr/td[1]" use="concat(.,'|',substring(../../../../../entry/act/effectiveTime[../entryRelationship/observation/value/originalText/text() = current()/@ID]/low/@value,1,8))"/>