0

我有一些xml:

<Test>
  <thing location="home" status="good"/>
  <thing location="work" status="bad"/>
  <thing location="mountains" status="good"/>
</Test>

上的叶子TreeView是状态属性的值;节点将是位置属性的值。

├──坏
│.....└──
工作└──好
.......├──家
.......└──山

目前,我手动填充TreeView(或TabControl),遍历 xml,将节点添加到适当的叶子。
这可以通过数据绑定来完成吗?我猜会涉及转换器...
感谢您的任何建议。

4

1 回答 1

0

假设您要绑定到 XmlDataSource,您可以使用具有以下内容的 TransformFile:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/Test">
    <Test>
      <good>
        <xsl:for-each select="thing[@status='good']">
           <xsl:element name="{@location}"/>
        </xsl:for-each>
      </good>
      <bad>
        <xsl:for-each select="thing[@status='bad']">
          <xsl:element name="{@location}"/>
        </xsl:for-each>
      </bad>
    </Test>
  </xsl:template>
</xsl:stylesheet>

向 XmlDataSource添加一个XPath="/Test/*"属性以删除“Test”根元素。

于 2009-08-17T21:31:04.083 回答