我对 xslt 完全陌生,所以请耐心解答这个问题。
我在 PowerShell 脚本中从 sqlpackage.exe 生成了一个 XML 文件。这是输出的缩减版本(有许多节点,但我在这里只包含了一个)
<?xml version="1.0" encoding="utf-8"?>
<DeploymentReport xmlns="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02">
<Operations>
<Operation Name="Drop">
<Item Value="[dbo].[WORKORDERSchema]" Type="SqlXmlSchemaCollection" />
<Item Value="[///SourceDB/TargetService]" Type="SqlService" />
<Item Value="[Foo].[DF_HistoryRawMatchedPPR_ActionDate]" Type="SqlDefaultConstraint" />
<Item Value="[dbo].[CMLEDGAPPLY_CreateUpdate_CMLEDGAPPLY]" Type="SqlProcedure" />
<Item Value="[///SourceDB/InitiatorService]" Type="SqlService" />
<Item Value="[///General/20141027]" Type="SqlContract" />
<Item Value="[///RequestMessage]" Type="SqlMessageType" />
</Operation>
</Operations>
</DeploymentReport>
I have created an xslt transform for this to generate the output in a table in html - again cut a down version
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html lang="en">
<head>
<title>Environment Refresh</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="DeploymentReport/Operations/Operation[@Name='Drop']">
<p>
<table border="1">
<tr>
<td colspan="2">Drop</td>
</tr>
<xsl:for-each select="Item">
<xsl:sort select="@Type" />
<tr>
<td><xsl:value-of select="@Type" /></td>
<td><xsl:value-of select="@Value" /></td>
</tr>
</xsl:for-each>
</table>
</p>
</xsl:template>
</xsl:stylesheet>
当我运行它时,我得到以下“空”的 html 输出,我不知道为什么
<html lang="en">
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Environment Refresh</title>
</head>
<body>
</body>
</html>
我已经根据我在这个网站上的环顾四周尝试了各种选项,但我可以让 xslt 工作的唯一方法是删除 xmlns="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02"来自 xml 第 2 行的 DeploymentReport 节点。
我也尝试将 xmlns="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02" 放入 xslt 中,也尝试使用 xmlns:t="http://schemas.microsoft.com /sqlserver/dac/DeployReport/2012/02" 格式,但没有运气。
有人可以在这里帮助我吗?正如我所说,我对此完全陌生,这是我第一次尝试 xslt,因此欢迎任何帮助或建议
命名空间前缀可以在 XSLT 中声明,并且select
前缀可以用于不同的节点,如下所示
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02"
version="1.0">
....
<xsl:template match="ms:DeploymentReport/ms:Operations/ms:Operation[@Name='Drop']">
....
<xsl:for-each select="ms:Item">
....
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句