开发者

add text line in XML file using XSLT

I have a simple XML file

 <Config new="Y" >
   <schema_path value="/var/tmp/sh.xsd"/>
   <collection name="new"开发者_高级运维 >        
       <unit-list>
         <Instance active="Y" unit_type="xp" unit_name="table"/>
       </unit-list>
   </collection>
</Config>

I'd like to instert a new element Instance into xml in unit-list

<Instance active="N" unit_type="linux" unit_name="door" />

How to do it ?


This copies everything from the input XML and adds the Instance at the end of unit-list:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template match="unit-list">
        <unit-list>
            <xsl:apply-templates />
            <Instance active="N" unit_type="linux" unit_name="door" />
        </unit-list>
    </xsl:template>

    <xsl:template match="@*|*|text()">
        <xsl:copy>
            <xsl:apply-templates select="@*|*|text()" />
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜