Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用计算最大值所需的XSLT(XML到XML)_Xml_Xslt - Fatal编程技术网

使用计算最大值所需的XSLT(XML到XML)

使用计算最大值所需的XSLT(XML到XML),xml,xslt,Xml,Xslt,是否有XSLT可以将“XML文档1”转换为“XML文档2”,如下所示?在“XML文档1”中,我需要确定EncounterId值,其中EncounterId是最大值,然后确定哪些诊断具有该EncounterId值。我可以分别执行每个步骤,但不能在一个变换中将它们放在一起。可能吗 提前谢谢 XML文档1 <Data> <Encounters> <Encounter> <EncounterId>1234</Encounter

是否有XSLT可以将“XML文档1”转换为“XML文档2”,如下所示?在“XML文档1”中,我需要确定EncounterId值,其中EncounterId是最大值,然后确定哪些诊断具有该EncounterId值。我可以分别执行每个步骤,但不能在一个变换中将它们放在一起。可能吗

提前谢谢

XML文档1

<Data>
  <Encounters>
    <Encounter>
      <EncounterId>1234</EncounterId>
      <EncounterDt>01/01/2018</EncounterDt>
    </Encounter>
    <Encounter>
      <EncounterId>5678</EncounterId>
      <EncounterDt>01/02/2018</EncounterDt>
    </Encounter>
  </Encounters>
  <Diagnoses>
    <Diagnosis>
      <EncounterId>1234</EncounterId>
      <Code>ABCD</Code>
    </Diagnosis>
    <Diagnosis>
      <EncounterId>5678</EncounterId>
      <Code>EFGH</Code>
    </Diagnosis>
  </Diagnoses>
</Data>
上述最大遭遇时间为2018年2月1日,因此我们对 诊断为
EncounterId=5678

XML文档2

<Data>
  <Encounters>
    <Encounter>
      <EncounterId>5678</EncounterId>
      <EncounterDt>01/02/2018</EncounterDt>
    </Encounter>
  </Encounters>
  <Diagnoses>
    <Diagnosis>
      <EncounterId>5678</EncounterId>
      <Code>EFGH</Code>
    </Diagnosis>
  </Diagnoses>
</Data>

首先,从最大值
遇到的t
中获取一个包含
遇到的id
的变量,如下所示:

<xsl:variable name="kMaxEncounter">
    <xsl:for-each select="/Data/Encounters/Encounter">
        <!-- sorting the values by descending order
             to get the max value in the first position -->
        <xsl:sort select="EncounterDt" data-type="text" order="descending"/>
        <!-- get the value of the EncounterId -->
        <xsl:if test="position()=1">
            <xsl:value-of select="EncounterId"/>
        </xsl:if>
    </xsl:for-each>
</xsl:variable>

下一步是创建与$kMaxEncounter不匹配的不做任何事情的模板

<xsl:template match="Encounter[EncounterId!=$kMaxEncounter]|
    Diagnosis[EncounterId!=$kMaxEncounter]"/>

和身份模板:

<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>


请查看操作()。

请显示您的两个步骤。这是两份单独的文件还是一份?查看
document()
函数。感谢您的回复。”“XML文档1”是转换的输入文档,“XML文档2”是转换的输出。您的问题是:可能吗?是的,这是可能的。尝试一下,遇到问题时返回。