我正在尝试使用Powershell .Net方法使用XSL文件转换XML文件。这是我的代码,
#-- Create transformation --#
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
#-- Create a reader with DTDparsing set to parse --#
$xrs = New-Object System.Xml.XmlReaderSettings
$xrs.DtdProcessing = 'Parse'
#-- Load the XSL transform with the reader setting --#
$xr = [System.Xml.XmlReader]::Create("C:\Users\admin\Downloads\recoveryHistory_en.xsl", $xrs)
$xslt.Load($xr)
#-- Create a writer --#
$xws = New-Object System.Xml.XmlWriterSettings
$xw = [System.Xml.XmlWriter]::Create("C:\Users\admin\Downloads\Test RP_failover.html", $xslt.OutputSettings)
#-- Execute the transform and output the results to a file --#
$xslt.Transform("C:\Users\admin\Downloads\Test RP_failover.xml", $xw)
$xw.Close()
尽管$xslt.Transform()
确实按预期创建了HTML文件,但它似乎完全为空。这是xsl文件中的xsl:output
和xsl:choose
元素。我的XML和XSL文件存储在上面的链接中。我想知道xsl:choose
XSL文件中的元素是否像XSL一样导致输出HTML文件为空<xsl:when test="@outputType = 'csv'">
。
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
<xsl:template match="RecoveryPlanStepReport">
<xsl:choose>
<xsl:when test="@outputType = 'html'">
<xsl:call-template name="PrintRecoveryPlanStepReportForHtml"/>
</xsl:when>
<xsl:when test="@outputType = 'csv'">
<xsl:call-template name="PrintRecoveryPlanStepReportForCsv"/>
</xsl:when>
</xsl:choose>
</xsl:template>
我可以设置要显式调用的Transform
属性中是否有值?我正在尝试找出一种方法来强制XSL仅使用HTML。System.Xml.Xsl.XslCompiledTransform
<xsl:when test="@outputType = 'html'">
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
$xslt.Transform.Value
OverloadDefinitions
-------------------
void Transform(System.Xml.XPath.IXPathNavigable input, System.Xml.XmlWriter results)
void Transform(System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results)
void Transform(System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results)
void Transform(System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results)
void Transform(System.Xml.XmlReader input, System.Xml.XmlWriter results)
void Transform(System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results)
void Transform(System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results)
void Transform(System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results)
void Transform(string inputUri, System.Xml.XmlWriter results)
void Transform(string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results)
void Transform(string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results)
void Transform(string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results)
void Transform(string inputUri, string resultsFile)
void Transform(System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results, System.Xml.XmlResolver documentResolver)
void Transform(System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results, System.Xml.XmlResolver documentResolver)
这是我解决的方法,
我从这里修改了XSL中的以下代码段
<xsl:template match="RecoveryPlanResult">
<xsl:choose>
<xsl:when test="Results"> <!-- SRM 4.x identifying tag -->
<xsl:choose>
<xsl:when test="@outputType = 'html'">
<xsl:call-template name="LegacyPrintHistoryReportForHtml"/>
</xsl:when>
<xsl:when test="@outputType = 'csv'">
<xsl:call-template name="LegacyPrintHistoryReportForCsv"/>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise> <!-- SRM 5.x -->
<xsl:choose>
<xsl:when test="@outputType = 'html'">
<xsl:call-template name="PrintHistoryReportForHtml"/>
</xsl:when>
<xsl:when test="@outputType = 'csv'">
<xsl:call-template name="PrintHistoryReportForCsv"/>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
对此
<xsl:template match="RecoveryPlanResult">
<xsl:call-template name="PrintHistoryReportForHtml"/>
</xsl:template>
问题:尽管match
元素在元素中具有正确的模式,但xsl:template
元素中的表达式xsl:when
不正确
<xsl:when test="@outputType = 'html'">
XML格式
<?xml version="1.0" encoding="UTF-8"?>
<RecoveryPlanResult>
<RecoveryPlan>
<Name>Test RP</Name>
<Description />
<LocalVcAddress>LocalVC</LocalVcAddress>
<LocalSiteName>LocalSite</LocalSiteName>
<RemoteVcAddress>remote</RemoteVcAddress>
<RemoteSiteName>remote</RemoteSiteName>
<TimeZoneOffset>0</TimeZoneOffset>
</RecoveryPlan>
</RecoveryPlanResult>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句