please I was wondering if someone can please help as its quite urgent. I need to convert the structue of an xml file to another xml structure so that I can bind it to a asp.net treeview control (i'm a c# developer). I noticed the asp.net treeview control accepts a transform file or xpath expr开发者_StackOverflowession and am wondering if some one knows of a solution that will work please: From
<Skeleton>
<Category>Carto</Category>
<SubCategoryName>ET-ET-RS23</SubCategoryName>
<Filename>V-01.XML</Filename>
<XmlDefinition>SKELETON</XmlDefinition>
</Skeleton>
<Skeleton>
<Category>Carto
<SubCategoryName>ET-ET-RS23
<Filename>V-01.XML
<XmlDefinition><SKELETON /></XmlDefinition>
</Filename>
</SubCategoryName>
</Category>
</Skeleton>
Basically the I want to have a nested tree structure so I can simply bind to my treeview control. So Category contains SubCategoryName and that contains Filename and that contains xmldefinition
sorry I hope this makes sense, thank you
This stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()[1]|
following-sibling::node()[1]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="XmlDefinition/text()">
<xsl:value-of select="concat('<',.,'/>')"/>
</xsl:template>
</xsl:stylesheet>
Output:
<Skeleton>
<Category>Carto
<SubCategoryName>ET-ET-RS23
<Filename>V-01.XML
<XmlDefinition><SKELETON/></XmlDefinition>
</Filename>
</SubCategoryName>
</Category>
</Skeleton>
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node()[1]"/>
<xsl:apply-templates select="following-sibling::node()[1]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="XmlDefinition/text()">
<<xsl:value-of select="."/>/>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<Skeleton>
<Category>Carto</Category>
<SubCategoryName>ET-ET-RS23</SubCategoryName>
<Filename>V-01.XML</Filename>
<XmlDefinition>SKELETON</XmlDefinition>
</Skeleton>
produces the wanted result:
<Skeleton>
<Category>Carto
<SubCategoryName>ET-ET-RS23
<Filename>V-01.XML
<XmlDefinition>
<SKELETON/>
</XmlDefinition>
</Filename>
</SubCategoryName>
</Category>
</Skeleton>
精彩评论