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.
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'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'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'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>
Notice there are h1, h2, and h3 heads in my sample but there can also be h4, h5 and h6 heads too.
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?
I have to use XSLT 1.0
Here's a method that does use a key to retain only unique headings. A heading is considered unique if it is the first of a group of headings grouped by the concatenation of: (1) the element name, (2) the
category
child of the parentCaseStudies
element, and (3) the value.XSLT 1.0
When applied to a simplified and corrected version of your input example:
the following result is obtained:
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-precedingCaseStudies
element, and suppress any that are the same.Note I'm using
not(x = y)
instead ofx != y
to allow for the fact that there might not be a../preceding-sibling::*[1]
at all.