转换 XML 文档以与 .NET 2.0 TreeView 控件一起使用
我有一个格式如下的 XML 文件:
<root>
<category>
<doctype>
<name>Doc1</name>
<site>
<name>Site1</name>
<target>iframe</target>
<url>http://www.gmail.com</url>
</site>
</doctype>
<doctype>
<name>Doc2</name>
<site>
<name>Site2</name>
<target>iframe</target>
<url>http://www.bbc.co.uk</url>
</site>
</doctype>
</category>
</root>
我需要在标准 .net 2.0 TreeView 控件上使用它,该控件需要以下格式的 XML
<root>
<category>
<doctype name="Doc1">
<site name = "Site1" target = "iframe" url = "http://www.gmail.com">
</site>
</doctype>
<doctype name="Doc2">
<site name = "Site2" target = "iframe" url = "http://www.bbc.co.uk">
</site>
</doctype>
</category>
</root>
最大的复杂性是 DOCTYPE 节点的某些子节点需要转换为属性(即 NAME),而一些保留为需要自己的属性(即 SITE)的子节点。
如何使用 XSLT 来完成此操作?
I have an XML file which is in the following format:
<root>
<category>
<doctype>
<name>Doc1</name>
<site>
<name>Site1</name>
<target>iframe</target>
<url>http://www.gmail.com</url>
</site>
</doctype>
<doctype>
<name>Doc2</name>
<site>
<name>Site2</name>
<target>iframe</target>
<url>http://www.bbc.co.uk</url>
</site>
</doctype>
</category>
</root>
I need to use it on a standard .net 2.0 TreeView control which requires the XML in the following format
<root>
<category>
<doctype name="Doc1">
<site name = "Site1" target = "iframe" url = "http://www.gmail.com">
</site>
</doctype>
<doctype name="Doc2">
<site name = "Site2" target = "iframe" url = "http://www.bbc.co.uk">
</site>
</doctype>
</category>
</root>
The biggest complication is the fact that some child nodes of the DOCTYPE node need to be converted to attributes (i.e. NAME) while some stay as child nodes which require attributes of their own (i.e. SITE).
How can this be done using XSLT?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下 XSLT 1.0 转换可实现您的预期。
输出:
The following XSLT 1.0 transformation does what you intend.
Output: