挑选独特的头 [英] Picking unique heads

查看:20
本文介绍了挑选独特的头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按类别排序和分组了一些 XML.所以,我在考虑使用 XSLT 1.0 分组来拉出类别头.但我想知道是否有更简单的方法来简单地选择每个类别和组的第一个标题并删除或忽略重复项.

I some XML that is already ordered and grouped by categories. So, I was thinking of using XSLT 1.0 grouping to pull out the category heads. But I was wondering if there is an easier way to simply pick the first heading of each category and group and delete or ignore the duplicates.

以下是 XML 示例:

Here is a sample of the 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>

请注意,我的样本中有 h1、h2 和 h3 正面,但也可能有 h4、h5 和 h6 正面.

Notice there are h1, h2, and h3 heads in my sample but there can also be h4, h5 and h6 heads too.

因此,我想按原样返回内容,但仅在每个 UNIQUE HEAD h1-h6 首次出现在由 h1、h2、h3 等控制的每个部分中时只显示一次.

So, I want to return the content as is but only display each UNIQUE HEAD h1-h6 only once the first time it appears within each section governed by each of the h1, h2, h3, etc.

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

这可以在不创建组和密钥的情况下完成吗?

Can this be done without creating a group and key?

我必须使用 XSLT 1.0

I have to use XSLT 1.0

推荐答案

在这种情况下,由于输入始终是合理的顺序,您真正需要做的就是比较每个 H* 元素到 立即前 CaseStudies 元素中同名元素的值,并抑制任何相同的元素.

In this case, since the input is always in sensible order, all you really have to do is compare the value of each H* element to the value of the same named element in the immediately-preceding CaseStudies element, and suppress any that are the same.

<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>

注意我使用 not(x = y) 而不是 x != y 来考虑可能没有 be 一个 ../preceding-sibling::*[1] .

Note I'm using not(x = y) instead of x != y to allow for the fact that there might not be a ../preceding-sibling::*[1] at all.

这篇关于挑选独特的头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆