簡體   English   中英

創建基於XML的動態XSL

[英]Create a dynamic XSL based on XML

我的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文件,該文件將在一個html Table顯示所有Type ,這可以幫助我我嘗試了一些如下操作,但是沒有用

<?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下的所有Types下方 在此處輸入圖片說明

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>

因此,您首先要按 @Type進行分組,假設您確實需要使用XSLT 1.0,然后使用Muenchian分組

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM