在我的 XML 中,我有这样的东西:
<people>
<person>
<name>
<first>Bob</first>
<last>Bobbertson</last>
</name>
<age>80</age>
</person>
...
</people>
我希望能够将整个<person>
部分传递给我的代码隐藏,以便在我的 C# 代码中,我可以访问所有子节点 ( <name>
, <first>
, <last>
)。
我正在使用 XSLT 生成我的 HTML,在我的 XSLTfile 中,我有这样一行:
<xsl:value-of select="custom:SelectPerson($selectedPerson)"/>
在我的代码隐藏中调用它:
public string SelectPerson(System.Xml.XPath.XPathNodeIterator selectedPersonNodes)
{
foreach (var node in selectedPersonNodes)
{
Debug.WriteLine(node.ToString());
}
...
}
我想要发生的是foreach
循环三次,然后打印出“Bob”,然后是“Bobbertson”,然后是“80”。但是发生的事情是它经过一次并打印出“BobBobbertson80”。
有没有办法以我想要的方式将节点从 XSLT 生成的 HTML 传递到我的代码隐藏?