Monday, 12 January 2015

Dependency inversion

Yesterdays post showed how to get all the reports with all the subreports

Here's the transform to change this to all subreports with their calling reports
as well as all reports that are not subreports at all.

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:output method="xml" encoding="utf-8" />
<xsl:key name="subreports-by-name" match="/ReportHierarchy/ReportDirectory/Report/Subreport" use="Name"/>
<xsl:template match="/">
<ReportDependencies>
<Subreport>
<Name>
<xsl:text>None</xsl:text>
</Name>
<xsl:for-each select="/ReportHierarchy/ReportDirectory/Report[generate-id() != generate-id(key('subreports-by-name', Name)[1])]">
<xsl:sort select="Name" />
<Report>
<Name>
<xsl:value-of select="Name" />
</Name>
<ReportDirectory>
<xsl:value-of select="../Name"/>
</ReportDirectory>
</Report>
</xsl:for-each>
</Subreport>
<xsl:for-each  select="/ReportHierarchy/ReportDirectory/Report/Subreport [count(. | key('subreports-by-name', Name)[1]) = 1]">
<xsl:sort select="Name" />
<Subreport>
<Name>
<xsl:value-of select="Name"/>
</Name>
<xsl:value-of select="surname" />
<xsl:for-each select="key('subreports-by-name', Name)">
<xsl:sort select="../Name" />
<Report>
<Name>
<xsl:value-of select="../Name" />
</Name>
<ReportDirectory>
<xsl:value-of select="../../Name"/>
</ReportDirectory>
</Report>
</xsl:for-each>
</Subreport>
</xsl:for-each>
</ReportDependencies>
</xsl:template>
</xsl:stylesheet>

And the sample output....
<?xml version="1.0" encoding="utf-8"?>
<ReportDependencies>
<Subreport>
<Name>None</Name>
<Report>
<Name>AdventureWorks2008R2_Base.rdl</Name>
<ReportDirectory>AdventureWorks 2008R2</ReportDirectory>
</Report>
        </Subreport>
<Subreport>
<Name>subreportDT1</Name>
<Report>
<Name>FinishingPackNetSpeedForGroup1.rdl</Name>
<ReportDirectory>SsrsReportDocumentation</ReportDirectory>
</Report>
<Report>
<Name>FinishingPackNetSpeedForGroup2.rdl</Name>
<ReportDirectory>SsrsReportDocumentation</ReportDirectory>
</Report>
</Subreport>
</ReportDependencies> 

No comments:

Post a Comment

Note: only a member of this blog may post a comment.