私は、入力XML文書が...XslCompiledTransformを使用して出力XMLに自己終了タグを取得するにはどうすればよいですか?
を助けてください。私は次のXMLにそれを変換する必要
<?xml version="1.0" encoding="utf-8"?>
<Root>
<Object>
<GUID>201110180954525010129</GUID>
<Meta name="FILENAME" format="string" frate="" />
</Object>
</Root>
を:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Object>
<GUID>201110180954525010129</GUID>
<FILENAME/>
</Object>
<Root>
私は次のスタイルシートを作成しました:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="Root">
<xsl:for-each select="Root/Object">
<xsl:element name="Object">
<xsl:element name="FILENAME">
<xsl:value-of select="Meta[@name='FILENAME']" />
</xsl:element>
<xsl:element name="GUID">
<xsl:value-of select="GUID" />
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
しかし、変換しようとすると、n拡張結果:
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Object>
<GUID>201110180954525010129</GUID>
<FILENAME> </FILENAME>
</MAObject>
<Root>
セルフクローズタグの解釈方法を教えてください。
C#の変換コード:
var stylesheet = "styleSheet.xml";
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("input.xml");
XslCompiledTransform xslTransform = new XslCompiledTransform();
xslTransform.Load(styleSheet);
XmlDocument xmlDocumentOutput = new XmlDocument();
XmlDeclaration xmlDocumentOutputDeclaration = xmlDocumentOutput.CreateXmlDeclaration("1.0", "utf-8", null);
xmlDocumentOutput.AppendChild(xmlDocumentOutputDeclaration);
using (XmlWriter xmlWriter = xmlDocumentOutput.CreateNavigator().AppendChild())
{
xslTransform.Transform(xmlDocument.CreateNavigator(), null, xmlWriter);
}
return xmlDocumentOutput;
こんにちは!答えをありがとう。私はちょうど質問を更新しました...タグ間に空白が表示される理由はわかりません。 –