XSLT transformation from SSRS report - group results
I am trying to create an xml file from a SSRS report.
I am having a problem with the following:
<xsl:template match="AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events[Invalid_Reason_Formated='Emergency Record: will be removed from waitlist'] |
AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events[Invalid_Reason_Formated='Entry Error: will be removed from waitlist'] |
AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events[Invalid_Reason_Formated='Entry Error or Emergency Record: will be removed from waitlist']">
<AWL_KeyDel_Events>
<xsl:apply-templates/>
</AWL_KeyDel_Events>
</xsl:template>
My output for this is(my sample has records that meet 2 of the criteria above):
<AWL_KeyDel_Events>
<Event_Key>101</Event_Key>
<Event_Key>102</Event_Key>
<Event_Key>103</Event_Key>
</AWL_KeyDel_Events>
<AWL_KeyDel_Events>
<Event_Key>99</Event_Key>
<Event_Key>100</Event_Key>
</AWL_KeyDel_Events>
And i would like it to display as(order of records is not important):
<AWL_KeyDel_Events>
<Event_Key>101</Event_Key>
<Event_Key>102</Event_Key>
<Event_Key>103</Event_Key>
<Event_Key>99</Event_Key>
<Event_Key>100</Event_Key>
</AWL_KeyDel_Events>
Is there a way that i can do this?
Edit: Here is the source XML file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output method="xml" indent="yes" encoding="ascii" standalone="no" media-type="text/plain" omit-xml-declaration="yes"/>
<xsl:output
doctype-system="http://portal2.albertawellnet.org/dtd/waitlist/KeyModeSurgicalEvent.dtd"
doctype-public="-//AHW//DTD WAITLIST 1.0//EN"></xsl:output>
<xsl:template match="*">
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="/">
<AWL_Document>
<AWL_Header>
<Facility_Code>
<xsl:value-of select="//FacilityIdentifier" />
</Facility_Code>
<Service_Type>S</Service_Type>
<File_Name>
<xsl:value-of select="//SubmissionFileName"/>
</File_Name>
<Create_Timestamp>
<xsl:value-of select="//CurrentDate" />
</Create_Timestamp>
</AWL_Header>
<AWL_Waitlist_Events>
<xsl:apply-templates/>
</AWL_Waitlist_Events>
<AWL_Footer>
<Total_Waitlist_Count>
<xsl:value-of select="count(//AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail[Invalid_Reason=''] |
//AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail[Invalid_Reason='Emergency Deletes'] |
//AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail[Invalid_Reason='Deletes'] |
//AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail[Invalid_Reason='entry error'])"/>
</Total_Waitlist_Count>
<KeySub_Waitlist_Count>
<xsl:value-of select="count(//AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail[Invalid_Reason=''])"/>
</KeySub_Waitlist_Count>
<KeyDel_Waitlist_Count>
<xsl:value-of select="count(//AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail[Invalid_Reason='Emergency Deletes'] |
//AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail[Invalid_Reason='Deletes'] |
//AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail[Invalid_Reason='entry error'])"/>
</KeyDel_Waitlist_Count>
</AWL_Footer>
</AWL_Document>
</xsl:template>
<xsl:template match="AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events">
</xsl:template>
<xsl:template match="AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events[Invalid_Reason_Formated='Valid records to be sent']">
<AWL_KeySub_Events>
<xsl:apply-templates/>
</AWL_KeySub_Events>
</xsl:template>
<xsl:template match="AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events[Invalid_Reason_Formated='Emergency Record: will be removed from waitlist'] |
AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events[Invalid_Reason_Formated='Entry Error: will be removed from waitlist'] |
AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events[Invalid_Reason_Formated='Entry Error or Emergency Record: will be removed from waitlist']
">
<AWL_KeyDel_Events>
<xsl:apply-templates/>
</AWL_KeyDel_Events>
</xsl:template>
<xsl:template match="AWL_Document/AWL_KeySub_Events_Collection/AWL_KeySub_Events/Detail_Collection/Detail">
<Waitlist_Event>
<Event_Key>
<xsl:value-of select="Facility_Event_Key"/>
</Event_Key>
<ULI>
<xsl:value-of select="ULI"/>
</ULI>
<Gender>
<xsl:value-of select="Gender"/>
</Gender>
<Birth_Date>
<xsl:value-of select="Birth_Date"/>
</Birth_Date>
<Section_Code>
<xsl:value-of select="Section_Code"/>
</Section_Code>
<Group_Code_1>
<xsl:value-of select="Group_Code_1"/>
</Group_Code_1>
<Group_Code_2>
<xsl:value-of select="Group_Code_2"/>
</Group_Code_2>
</Waitlist_Event>
</xsl:template>
And here is the expected output:
<AWL_Document>
<AWL_Header>
<Facility_Code>001</Facility_Code>
<Service_Type>S</Service_Type>
<File_Name>FileName.xml</File_Name>
<Create_Timestamp>201102140143</Create_Timestamp>
</AWL_Header>
<AWL_Waitlist_Events>
<AWL_KeySub_Events>
<Waitlist_Event>
<Event_Key>107</Event_Key>
<ULI>00开发者_Python百科0000000</ULI>
<Gender>F</Gender>
<Birth_Date>20000101</Birth_Date>
<Section_Code>1</Section_Code>
<Group_Code_1>Y</Group_Code_1>
<Group_Code_2>^</Group_Code_2>
</Waitlist_Event>
</AWL_KeySub_Events>
<AWL_KeyDel_Events>
<Waitlist_Event>
<Event_Key>101</Event_Key>
<ULI>000000000</ULI>
<Gender>F</Gender>
<Birth_Date>19700101</Birth_Date>
<Section_Code>1</Section_Code>
<Group_Code_1>Y</Group_Code_1>
<Group_Code_2>^</Group_Code_2>
</Waitlist_Event>
<Waitlist_Event>
<Event_Key>99</Event_Key>
<ULI>000000000</ULI>
<Gender>F</Gender>
<Birth_Date>19700202</Birth_Date>
<Section_Code>1</Section_Code>
<Group_Code_1>Y</Group_Code_1>
<Group_Code_2>^</Group_Code_2>
</Waitlist_Event>
<Waitlist_Event>
<Event_Key>102</Event_Key>
<ULI>000000000</ULI>
<Gender>F</Gender>
<Birth_Date>19800101</Birth_Date>
<Section_Code>1</Section_Code>
<Group_Code_1>Y</Group_Code_1>
<Group_Code_2>^</Group_Code_2>
</Waitlist_Event>
</AWL_KeyDel_Events>
</AWL_Waitlist_Events>
<AWL_Footer>
<Total_Waitlist_Count>4</Total_Waitlist_Count>
<KeySub_Waitlist_Count>1</KeySub_Waitlist_Count>
<KeyDel_Waitlist_Count>3</KeyDel_Waitlist_Count>
</AWL_Footer>
</AWL_Document>
I think you need:
<xsl:template match="AWL_KeySub_Events"/>
<xsl:template match="AWL_KeySub_Events[
Invalid_Reason_Formated[
.='Valid records to be sent'
or
contains(.,'will be removed from waitlist')
]
][1]">
<AWL_KeySub_Events>
<xsl:apply-templates
select="../AWL_KeySub_Events[
Invalid_Reason_Formated[
.='Valid records to be sent'
or
contains(.,'will be removed from waitlist')
]
]/node()"/>
</AWL_KeySub_Events>
</xsl:template>
Note: Matching the first one meeting requeriments and then apply templates to children of the whole group. An empty rule with less priority will match any one else.
Probably you want:
<xsl:template match="AWL_Document/AWL_KeySub_Events_Collection[.//AWL_KeySub_Events[contains(Invalid_Reason_Formated, 'will be removed from waitlist')]]">
<AWL_KeyDel_Events>
<xsl:apply-templates select=".//AWL_KeySub_Events[contains(Invalid_Reason_Formated, 'will be removed from waitlist')]" mode="insert-event-key"/>
</AWL_KeyDel_Events>
</xsl:template>
<xsl:template match="AWL_KeySub_Events" mode="insert-event-key">
<Event_Key><!-- fetch your key here--> </Event_Key>
</xsl:template>
But that's just a guess based on your template.
精彩评论