私のコンストラクタに名前空間を持つXDocumentを作成します。名前空間を使用するXElementを追加します。
this.nsXsl = XNamespace.Get("http://www.w3.org/1999/XSL/Transform");
this.doc = new XDocument(
new XElement(nsXsl + "stylesheet", new XAttribute("version", "1.0"), new XAttribute(XNamespace.Xmlns + "xsl", "http://www.w3.org/1999/XSL/Transform"),
new XElement(nsXsl + "output", new XAttribute("method", "xml"), new XAttribute("indent", "yes"), new XAttribute("encoding", "UTF-8")),
new XElement(nsXsl + "strip-space", new XAttribute("elements", "*")))
);
この文書は正しい構造を持ち、私が望むように見えます。
しかし、私のような機能を持っている:
private XElement createTemplate(string match, string node, string fork, string select)
{
return new XElement(this.nsXsl + "template", new XAttribute("match", match), new XElement(node,
new XElement(this.nsXsl + fork, new XAttribute("select", select))));
}
この関数は次のような構造のXElementオブジェクトを返します。
<template match="/shiporder/shipto" xmlns="http://www.w3.org/1999/XSL/Transform">
<Line1>
<apply-templates select="city" xmlns="" />
</Line1>
</template>
をしかし、私は同様のXElement必要があります。そこ
<xsl:template match="/shiporder/shipto">
<Line1>
<xsl:apply-templates select="city" />
</Line1>
</xsl:template>
あなたが唯一の化粧品、そしてときに新しいのXElementがXDOCにどのように装着されている/されたいの変化? –
@HenkHoltermanまでテンプレートのリストがあり、 'foreach(テンプレート内のXElement elem)のように追加します。 { doc.Add(elem); } ' – StellaMaris
これで問題は解決します。何もしないでください。 –