来自SSRS报告的XSLT转换 - 组结果

时间:2011-02-14 22:10:42

标签: xslt reporting-services

我正在尝试从SSRS报告中创建一个xml文件。

我遇到以下问题:

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

我的输出是(我的样本的记录满足上述两个标准):

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

我希望它显示为(记录的顺序并不重要):

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

有没有办法可以做到这一点?

编辑:这是源XML文件:     

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

这是预期的输出:

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

2 个答案:

答案 0 :(得分:0)

可能你想要:

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

但这只是基于你模板的猜测。

答案 1 :(得分:0)

我认为你需要:

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

注意:匹配第一个会议requeriments,然后将模板应用于整个组的子项。优先级较低的空规则将匹配任何其他规则。