<?xml version="1.0" encoding="utf-8" ?>
<XMLScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HMIWindow Type="Window" Name="Window_1">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</HMIWindow>
<Control Type="LINE" Name="LINE_1">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
</XMLScreen>
要通过XSLT 生成新的xml文档如下效果:
<?xml version="1.0" encoding="utf-8" ?>
<XMLScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HMIWindow Type="Window" Name="Window_1" CType=“CWND” CName=“CWND_1”>
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</HMIWindow>
<Control Type="LINE" Name="LINE_1" CType=“CLine” CName=“Line_1”>
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
</XMLScreen>希望是根据Type属性来判断 它是窗口还是控件,然后再插入自己想要的属性进去。
<XMLScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HMIWindow Type="Window" Name="Window_1">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</HMIWindow>
<Control Type="LINE" Name="LINE_1">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
</XMLScreen>
要通过XSLT 生成新的xml文档如下效果:
<?xml version="1.0" encoding="utf-8" ?>
<XMLScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HMIWindow Type="Window" Name="Window_1" CType=“CWND” CName=“CWND_1”>
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</HMIWindow>
<Control Type="LINE" Name="LINE_1" CType=“CLine” CName=“Line_1”>
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
</XMLScreen>希望是根据Type属性来判断 它是窗口还是控件,然后再插入自己想要的属性进去。
解决方案 »
- 类似 这中有数学公式的怎么在论坛发Sn=3*20+3*21+3*22+3*23+...+ 3*2n-1
- 如何将一个Ilist转化成一个二维的数组呢?
- 如何屏蔽 ie 上的返回键
- 方法传入参数? student[][]
- 各位大狭帮帮忙啊!!myxmht.resources在 Resource参数不支持重复项,指定了多次,怎么解决啊,解决马上给分,在线等啊!!
- 怎样获取画图板中所画的图
- 像微软拼音输入法自带的那种软键盘是什么窗口类型?
- 求助软件可靠性的资料...(在线等)
- 求助啊,如何调用另台电脑的打印机,按照A电脑样式打印,有图说明
- 怎么我的可用分好几天都没加啦,有谁知道?
- 关于HttpWebRequest 向百度贴吧Post的问题
- c#基础问题,请求帮忙!
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="//HMIWindow">
<xsl:for-each select="//HMIWindow">
<xsl:element name="HMIWindow">
<xsl:attribute name="Type"><xsl:value-of select="@Type"/></xsl:attribute>
<xsl:attribute name="Name"><xsl:value-of select="@Name"/></xsl:attribute>
<xsl:attribute name="CType">CWND</xsl:attribute>
<xsl:attribute name="CName">CWND_1</xsl:attribute>
<xsl:apply-templates select="Attribute"/>
</xsl:element>
</xsl:for-each>
</xsl:template> <xsl:template match="//Control">
<xsl:for-each select="//Control">
<xsl:element name="Control">
<xsl:attribute name="Type"><xsl:value-of select="@Type"/></xsl:attribute>
<xsl:attribute name="Name"><xsl:value-of select="@Name"/></xsl:attribute>
<xsl:attribute name="CType">CLine</xsl:attribute>
<xsl:attribute name="CName">Line_1</xsl:attribute>
<xsl:apply-templates select="Attribute"/>
</xsl:element>
</xsl:for-each>
</xsl:template> <xsl:template match="Attribute">
<xsl:element name="Attribute">
<xsl:attribute name="Name"><xsl:value-of select="@Name"/></xsl:attribute>
<xsl:attribute name="Value"><xsl:value-of select="@Value"/></xsl:attribute>
</xsl:element>
</xsl:template></xsl:stylesheet>
如下::
<XMLScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<--!因为是在一个窗口里添加很多控件,因此有很多未知性,所以生成xml的时候要根据Type先判断下,而且Name属性也要实现后缀递增-->
<HMIWindow Type="Window" Name="Window_1">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</HMIWindow>
<Control Type="LINE" Name="LINE_1">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
<Control Type="LINE" Name="LINE_2">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
<--!可能还有LINE_3 、LINE_4呀,不确定有多少-->
<Control Type="Circle" Name="Circle_1">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
<--!可能还有GradientTriangle(矩形) 、扇形、button等等,不确定有多少种控件,要根据判断是否有无来生成新的xml-->
</XMLScreen>
生成效果为:
<?xml version="1.0" encoding="utf-8" ?>
<XMLScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HMIWindow Type="Window" Name="Window_1" CType="CWindow" CName="CWindow_1">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</HMIWindow>
<Control Type="LINE" Name="LINE_1" CType="CLine" CName="CLine_1">
<--!可能还有第二条线、第三条线、......包含未确定性,也要根据判断生成出来-->
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
<Control Type="LINE" Name="LINE_2" CType="CLine" CName="CLine_2">
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
<Control Type="Circle" Name="Circle_1" CType="CCircle" CName="CCircle_1">
<--!可能还有矩形、button 、checkbox等控件也要根据判断有无这种控件来生成新的XML,生成样式与上面一样-->
<Attribute Name="BackColor" Value="ffffffff" />
<Attribute Name="ImageURI" Value="" />
<Attribute Name="Enabled" Value="True" />
<Attribute Name="Visible" Value="True" />
</Control>
</XMLScreen>