[Solved] Create a dynamic XSL and generate html


I don’t think you need grouping for your Alert issues. It looks like you simply want to output Alert issues which are referenced by “Item/Issue” records.

So, what you can do, is define a key like to look up “Item/Issue” records by id.

<xsl:key name="issue" match="report:Item/report:Issue" use="@Id"/>

Then, to get only Alert elements with referenced Issue elements, you can do this…

 <xsl:for-each select="//report:Alert[report:Issue[key('issue', @Id)]]">

And within this, you can get the issues like so

<xsl:for-each select="report:Issue[key('issue', @Id)]">

As for the listing of the Operation elements, it looks like you now want to group the issues by parent operation name, and by issue type, so you need a concatenated key like so:

<xsl:key name="type" match="report:Item" use="concat(../@Name, '|', @Type)"/>

You can then use it in the same way though. Try this XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:report="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02" 
                exclude-result-prefixes="report">

  <xsl:key name="type" match="report:Item" use="concat(../@Name, '|', @Type)"/>
  <xsl:key name="issue" match="report:Item/report:Issue" use="@Id"/>

  <xsl:template match="https://stackoverflow.com/">
    <html>
      <body>
      <table style="border:1px solid;" align="center">
          <xsl:for-each select="//report:Alert[report:Issue[key('issue', @Id)]]">
            <tr style="text-align:center;">
              <td style="color:red">
                  <xsl:value-of select="@Name"/>
              </td>
            </tr>
            <xsl:for-each select="report:Issue[key('issue', @Id)]">
                <tr>
                    <td>
                        <xsl:value-of select="@Value"/>
                    </td>
                </tr>
            </xsl:for-each>
          </xsl:for-each>
        </table>
        <table style="border:1px solid;" align="center">
          <xsl:for-each select="//report:Operation/report:Item[generate-id() = generate-id(key('type', concat(../@Name, '|', @Type))[1])]">
            <tr style="text-align:center;">
              <td style="color:red">
                  <xsl:value-of select="concat(../@Name, ' - ', @Type)"/>
              </td>
            </tr>
            <xsl:for-each select="key('type', concat(../@Name, '|', @Type))">
                <tr>
                    <td>
                        <xsl:value-of select="@Value"/>
                    </td>
                </tr>
            </xsl:for-each>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

4

solved Create a dynamic XSL and generate html