用Java扩展XSLT_使用XSLT的.NET扩展对象 - 如何迭代集合?

帮帮我,Stackoverflow!

我有一个简单的.NET 3.5控制台应用程序,它可以读取一些数据并发送电子邮件 . 我在XSLT样式表中表示电子邮件格式,以便我们可以轻松更改电子邮件的措辞,而无需重新编译应用程序 .

我们在应用转换时使用扩展对象将数据传递给XSLT:

xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"

xmlns:EmailNotification="ext:EmailNotification">

这样,我们可以有这样的陈述:

Dear :

以上工作正常 . 我通过这样的代码传递对象(为简洁起见省略了一些不相关的代码):

// purely an example structure

public struct EmailNotification

{

public string FullName { get; set; }

}

// Somewhere in some method ...

var notification = new Notification("John Smith");

// ...

XsltArgumentList xslArgs = new XsltArgumentList();

xslArgs.AddExtensionObject("ext:EmailNotification", notification);

// ...

// The part where it breaks! (This is where we do the transformation)

xslt.Transform(fakeXMLDocument.CreateNavigator(), xslArgs, XmlWriter.Create(transformedXMLString));

所以, all of the above code works . 但是,我想得到一点点幻想(总是我的垮台)并传递一个集合,这样我就能做到这样的事情:

The following accounts need to be verified:

当我在扩展对象中传递集合并尝试转换时,我收到以下错误:

"Extension function parameters or return values which have Clr type 'String[]' are not supported."

或List,或IEnumerable,或我尝试传入的任何内容 .

所以,我的问题是:

How can I pass in a collection to my XSLT?

What do I put for the xsl:value-of select="" inside the xsl:for-each ?

我想做什么不可能?

Edit: After I saw the two answers below, I took Chris Hynes' code and modified it very slightly to suit my needs. Solution is as follows:

// extension object

public struct EmailNotification

{

public List StringsSetElsewhere { private get; set; }

public XPathNavigator StringsNodeSet

{

get

{

XmlDocument xmlDoc = new XmlDocument();

XmlElement root = xmlDoc.CreateElement("Strings");

xmlDoc.AppendChild(root);

foreach (var s in StringsSetElsewhere)

{

XmlElement element = xmlDoc.CreateElement("String");

element.InnerText = s;

root.AppendChild(element);

}

return xmlDoc.CreateNavigator();

}

}

}

在我的XSLT中......

工作得很完美!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值