我正在使用xsl transform下面的代码。
var processor = new Processor();
XsltCompiler xslComp = processor.NewXsltCompiler();
XsltExecutable xslExec = xslComp.Compile(xslUri);
XsltTransformer xslTrans = xslExec.Load();
XdmDestination xdmD = new XdmDestination();
Serializer serializer = processor.NewSerializer();
using (FileStream fs = File.Open(xmlPath, FileMode.Open))
{
xslTrans.SetInputStream(fs, schemaUri); // set baseUri
xslTrans.Run(xdmD);
}
XdmNode value = null;
if (xdmD != null)
{
value = xdmD.XdmNode;
}
以下是示例输入xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:nf="urn:ietf:params:xml:ns:netconf:base:1.0" >
<xsl:output method="xml" indent="no"/>
<xsl:template match="/">
<xsl:value-of select="concat('<?xml',substring-after(//root/text(),'<?xml'))" disable-output-escaping="yes"
/>
</xsl:template>
</xsl:stylesheet>
示例输入xml:
<root>
<![CDATA[
<?xml version="1.0" encoding="ISO-8859-1"?>
<nf:rpc-reply xmlns:nf="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="http://www.cisco.com/nxos:1.0:vms">
<nf:data>
<show>
<svs>
<connections>
<conn-name>qa-gdc1</conn-name>
</connections>
</svs>
</show>
</nf:data>
</nf:rpc-reply>
]]>
</root>
输出:
<?xml version="1.0" encoding="ISO-8859-1"?>
<nf:rpc-reply xmlns:nf="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="http://www.cisco.com/nxos:1.0:vms">
<nf:data>
<show>
<svs>
<connections>
<conn-name>qa-gdc1</conn-name>
</connections>
</svs>
</show>
</nf:data>
</nf:rpc-reply>
答案 0 :(得分:2)
(正如我已在私人电子邮件中解释的那样)
disable-output-escaping是对串行器的指令。因此,如果结果树未序列化,则无效。 (您正在创建一个序列化程序,但您没有将其用作转换的目标。)