基于XML

时间:2017-04-24 06:34:01

标签: xml xslt

我的XML如下所示

<?xml version="1.0" encoding="utf-8"?>
<DeploymentReport xmlns="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02">
<Alerts><Alert Name="DataMotion"><Issue Value="Some value" /><Issue Value="Table" /></Alert><Alert Name="DataIssue"><Issue Value="Actual description" Id="1" /><Issue Value="Actual description." Id="2" /></Alert></Alerts>
<Operations>
<Operation Name="Create">
<Item Value="[dbo].[tblEmployee].[IX_tblEmployee]" Type="SqlIndex" />
<Item Value="[dbo].[TestProc]" Type="SqlProcedure" />
<Item Value="[dbo].[TestProc1]" Type="SqlProcedure" />
</Operation>
</Operations>
</DeploymentReport>

我需要生成一个动态XSL文件或一个XSL文件,该文件会在一个Type中显示所有html Table可以帮助我一些人我尝试了以下内容没有用的

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr bgcolor="#9acd32">
            <th>Table</th>
          </tr>
          <xsl:for-each select="Operation/Item/Value">
            <tr>
              <td><xsl:value-of select="Value"/></td>
              <td><xsl:value-of select="Value"/></td>
              <td><xsl:value-of select="Value"/></td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

我希望XSL的结果显示如下tr td下的所有类型 enter image description here

关于html的粗略想法

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:bar="http://www.bar.org" xmlns:foo="http://www.foo.org/">
   <body>
      <table border="1">
         <tr>
         <th>SqlProcedure</th>
         </tr>
         <tr>
            <td>TestProc</td>
         </tr>
         <tr>
            <td>TestProc1</td>
            </tr>
         <tr>
         <th>SqlIndex</th></tr>
         <tr>
            <td>IX_tblEmployee</td>

         </tr>
      </table>
   </body>
</html>

1 个答案:

答案 0 :(得分:2)

所以你首先想要按@Type进行分组,假设你确实需要使用XSLT 1.0然后使用Muenchian grouping

<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="@Type"/>

  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr bgcolor="#9acd32">
            <th>Table</th>
          </tr>
          <xsl:for-each select="//report:Operation/report:Item[generate-id() = generate-id(key('type', @Type)[1])]">
            <tr>
              <td>
                  <xsl:value-of select="@Type"/>
              </td>
            </tr>
            <xsl:for-each select="key('type', @Type)">
                <tr>
                    <td>
                        <xsl:value-of select="@Value"/>
                    </td>
                </tr>
            </xsl:for-each>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>