Xml 挑选独特的头

Xml 挑选独特的头,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,我看到一些已经按类别排序和分组的XML。因此,我考虑使用XSLT1.0分组来提取类别标题。但我想知道是否有一种更简单的方法可以简单地选择每个类别和组的第一个标题,并删除或忽略重复的标题 以下是XML的一个示例: <dataroot> <CaseStudies> <category>1</category> <GroupNo>2</GroupNo> <H1>Evaluation and

我看到一些已经按类别排序和分组的XML。因此,我考虑使用XSLT1.0分组来提取类别标题。但我想知道是否有一种更简单的方法可以简单地选择每个类别和组的第一个标题,并删除或忽略重复的标题

以下是XML的一个示例:

<dataroot>
  <CaseStudies>
    <category>1</category>
    <GroupNo>2</GroupNo>
    <H1>Evaluation and Management</H1>
    <H2>Office or Other Outpatient Services</H2>
    <H3>New Patient</H3>
    <indicators>{+}</indicators>
    <code>99201</code>
    <Fulldesc>Office or other outpatient.</Fulldesc>
    <HTMLdesc>
      <b>Office or other outpatient visit.</b>
    </HTMLdesc>
    <GlobalPeriod>XXX</GlobalPeriod>
    <assist_ref>CPT Assistant Winter</assist_ref>
    <changes_ref>CPT Changes: An Insider&apos;s View 2011, 2013</changes_ref>
    <case_study>Initial office visit.</case_study>
    <pre>Review the medical history.</pre>
    <intra>Obtain a problem focused history.</intra>
    <post>Complete medical record documentation.</post>
    <tip>Levels of E/M service.</tip>
  </CaseStudies>
  <CaseStudies>
    <category>1</category>
    <GroupNo>2</GroupNo>
    <H1>Evaluation and Management</H1>
    <H2>Office or Other Outpatient Services</H2>
    <H3>Established Patient</H3>
    <indicators>{+}</indicators>
    <code>99202</code>
    <Fulldesc>Office or other outpatient visit f.</Fulldesc>
    <HTMLdesc>
      <b>Office or other outpatient visit.</b>
    </HTMLdesc>
    <GlobalPeriod>XXX</GlobalPeriod>
    <assist_ref>CPT Assistant Winter 91:11</assist_ref>
    <changes_ref>CPT Changes</changes_ref>
    <case_study>Initial office visit.</case_study>
    <pre>Review the medical history.</pre>
    <intra>Obtain an expanded problem.</intra>
    <post>Complete medical record documentation.</post>
    <tip>pending proof</tip>
  </CaseStudies>
  <CaseStudies>
    <category>1</category>
    <GroupNo>3</GroupNo>
    <H1>Anesthesia</H1>
    <H2>Intrathoracic</H2>
    <H3>New Patient</H3>
    <indicators>{+}</indicators>
    <code>99203</code>
    <Fulldesc>Office or other outpatient visit.</Fulldesc>
    <HTMLdesc>
      <b>Office or other outpatient visit.</b>
    </HTMLdesc>
    <GlobalPeriod>XXX</GlobalPeriod>
    <assist_ref>CPT Assistant Winter 91:11</assist_ref>
    <changes_ref>CPT Changes: An Insider&apos;s View 2013</changes_ref>
    <case_study>Initial office visit.</case_study>
    <pre>Review the medical history form completed by the patient and vital signs obtained by clinical staff. Communicate with other health care professionals as necessary.</pre>
    <intra>Obtain a detailed history.</intra>
    <post>Complete medical record documentation.</post>
    <tip>pending proof</tip>
  </CaseStudies>
  <CaseStudies>
    <category>1</category>
    <GroupNo>3</GroupNo>
    <H1>Anesthesia</H1>
    <H2>Intrathoracic</H2>
    <H3>Established Patient</H3>
    <indicators>{+}</indicators>
    <code>99203</code>
    <Fulldesc>Office or other outpatient visit.</Fulldesc>
    <HTMLdesc>
      <b>Office or other outpatient visit.</b>
    </HTMLdesc>
    <GlobalPeriod>XXX</GlobalPeriod>
    <assist_ref>CPT Assistant Winter 91:11</assist_ref>
    <changes_ref>CPT Changes: An Insider&apos;s View 2013</changes_ref>
    <case_study>Initial office visit.</case_study>
    <pre>Review the medical history form completed by the patient and vital signs obtained by clinical staff. Communicate with other health care professionals as necessary.</pre>
    <intra>Obtain a detailed history.</post>
    <tip>pending proof</tip>
  </CaseStudies>
</dataroot>
获取以问题为中心的历史记录。 完整的病历文件。 E/M服务水平。 1. 2. 评价和管理 办公室或其他门诊服务 确诊病人 {+}
99202
办公室或其他门诊就诊f。 办公室或其他门诊就诊。 XXX CPT助理温特91:11 CPT变化 首次办公室访问。 获取详细的历史记录。 完整的病历文件。 待证明 1. 3. 麻醉 胸腔内 确诊病人 {+}
99203
办公室或其他门诊就诊。 办公室或其他门诊就诊。 XXX CPT助理温特91:11 CPT变化:内幕人士&apos;s视图2013 首次办公室访问。 是否可以在不创建组和密钥的情况下执行此操作


我必须使用XSLT1.0,这里有一个方法,它使用一个键只保留唯一的标题。如果一个标题是一组标题中的第一个标题,该标题由以下内容串联而成:(1)元素名称,(2)父
案例研究
元素的
类别
子项,以及(3)值,则认为该标题是唯一的

XSLT1.0


当应用于输入示例的简化和更正版本时:


1.
评价和管理
办公室或其他门诊服务
新病人
1.
评价和管理
办公室或其他门诊服务
确诊病人
1.
麻醉
胸腔内
新病人
1.
麻醉
胸腔内
确诊病人
得到以下结果:


1.
评价和管理
办公室或其他门诊服务
新病人
1.
确诊病人
1.
麻醉
胸腔内
1.

在这种情况下,由于输入总是以合理的顺序进行,因此您真正需要做的就是将每个
H*
元素的值与前面的
案例研究
元素中相同命名元素的值进行比较,并抑制任何相同的值



注意我使用的是
not(x=y)
而不是
x!=y
考虑到可能根本没有一个
。/前面的兄弟姐妹:*[1]

头部出现时总是按顺序排列。1。您的意思是,您想只在每个唯一的头第一次出现时显示它,而不管它在整个文档中的什么位置?2.使用键有什么问题?每个头部在每个类别中都会出现多次。我只想在每个头第一次出现在其类别中时显示它。我知道如何使用钥匙分组,这就是你要问的吗?我不知道如何使用钥匙。我没有说使用钥匙有什么问题,我只是想知道是否有更简单的方法。例如,当我编写SQL查询时,我可以使用过滤器“distinctrow”只提取唯一的标题。我不知道还有什么其他方法可以使用XSLT关闭重复的标题。或者更简单的是,通过使用一个无操作模板来消除if,该模板根据关键字匹配不是第一次出现的标题,然后将所有其他内容留给标识模板。@IanRoberts我不确定我是否理解您的建议:
if
用于(a)允许通过显式元素名称进行匹配,以及(b)避免重复同一谓词6次。嗯,是的,我忘了您不能使用
(H1 | H2 |…)[…]
匹配中
选择的方式
我刚刚注意到XML输出中有一个错误。在您的样本输出中,未显示新患者和已确定患者的“唯一”H3。每个标题必须为每个H1标题显示至少一次。我的指示可能有错。每个标题创建一个节。当H1发生变化时,每个H2必须复位。当H2发生变化时,h3必须复位,依此类推。XSL是否可以修改为在每个上级标题下显示唯一标题?@JimMaivald这不是一个错误。这是对你的需求的猜测的结果。我的猜测是因为你没有回应我的请求,即“澄清什么是“其类别中的唯一头部”。无论如何,如果您了解建议的解决方案是如何工作的,您应该能够修改它以更好地满足您的需要。
H1 Surgery
  h2 Hospital Inpatient Services
    h3 Subsequent Observation Care
      h4 New Patient
      h4 Existing Patient
h1 Opthamology
  h2 Hospital Observation Services
    h3 Subsequent Observation Care
      h4 New Patient
      h4 Existing Patient
      h4 Subsequent Hospital Care
h1 Anesthesia
  h2 Hospital Observation Services
    h3 Subsequent Observation Care
      h4 New Patient
      h4 Existing Patient
      h4 Subsequent Hospital Care
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:key name="h" match="H1|H2|H3|H4|H5|H6" use="concat(name(), '|', ../category, '|', .)" />

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

<xsl:template match="H1|H2|H3|H4|H5|H6">
    <xsl:if test="count(. | key('h', concat(name(), '|', ../category, '|', .))[1]) = 1">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>
<dataroot>
   <CaseStudies>
      <category>1</category>
      <H1>Evaluation and Management</H1>
      <H2>Office or Other Outpatient Services</H2>
      <H3>New Patient</H3>
   </CaseStudies>
   <CaseStudies>
      <category>1</category>
      <H1>Evaluation and Management</H1>
      <H2>Office or Other Outpatient Services</H2>
      <H3>Established Patient</H3>
    </CaseStudies>
   <CaseStudies>
      <category>1</category>
      <H1>Anesthesia</H1>
      <H2>Intrathoracic</H2>
      <H3>New Patient</H3>
   </CaseStudies>
   <CaseStudies>
      <category>1</category>
      <H1>Anesthesia</H1>
      <H2>Intrathoracic</H2>
      <H3>Established Patient</H3>
   </CaseStudies>
</dataroot>
<?xml version="1.0" encoding="UTF-8"?>
<dataroot>
   <CaseStudies>
      <category>1</category>
      <H1>Evaluation and Management</H1>
      <H2>Office or Other Outpatient Services</H2>
      <H3>New Patient</H3>
   </CaseStudies>
   <CaseStudies>
      <category>1</category>
      <H3>Established Patient</H3>
   </CaseStudies>
   <CaseStudies>
      <category>1</category>
      <H1>Anesthesia</H1>
      <H2>Intrathoracic</H2>
   </CaseStudies>
   <CaseStudies>
      <category>1</category>
   </CaseStudies>
</dataroot>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>

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

  <xsl:template match="H1|H2|H3|H4|H5|H6">
    <xsl:if test="not(. = ../preceding-sibling::*[1]/*[name() = name(current())])">
      <xsl:call-template name="ident" />
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>