I am completely new to xslt so please bear with me on this question.
我对xslt完全是新手,所以请在这个问题上耐心等待。
I have an XML file I am generating from sqlpackage.exe in a PowerShell script. This is a cut down version of the output (there are a number nodes but I have only included one here)
我有一个XML文件,我在PowerShell脚本中从sqlpackage.exe生成。这是输出的缩减版本(有一些节点,但我这里只包含一个)
<?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>
when I run this I get the following 'empty' html output and I do not know why
当我运行这个时,我得到以下'空'html输出,我不知道为什么
<html lang="en">
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Environment Refresh</title>
</head>
<body>
</body>
</html>
I have tried various options based on my looking around this site but the only way I can get the xslt to work is if I remove xmlns="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02" from the DeploymentReport node on line 2 of the xml.
我已经尝试了各种基于我浏览这个网站的选项,但我能让xslt工作的唯一方法就是删除xmlns =“http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02”来自xml第2行的DeploymentReport节点。
I have tried putting xmlns="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02" into the xslt as well and also tried using xmlns:t="http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02" format as well but with no luck.
我已经尝试将xmlns =“http://schemas.microsoft.com/sqlserver/dac/DeployReport/2012/02”放入xslt并尝试使用xmlns:t =“http://schemas.microsoft.com / sqlserver / dac / DeployReport / 2012/02“格式也没有运气。
Is anyone able to assist me here please? As I said I am completely new to this and this is my first attempt at xslt so any help or suggestions are welcome
有人能帮到我吗?正如我所说,我对此完全陌生,这是我对xslt的第一次尝试,所以欢迎任何帮助或建议
1 个解决方案
#1
0
The namespace prefix can be declared in the XSLT and in the select
the prefix can be used for the different nodes as below
名称空间前缀可以在XSLT中声明,在选择中,前缀可以用于不同的节点,如下所示
<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>
#1
0
The namespace prefix can be declared in the XSLT and in the select
the prefix can be used for the different nodes as below
名称空间前缀可以在XSLT中声明,在选择中,前缀可以用于不同的节点,如下所示
<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>