我想使用XSLT在system-properties.xml中添加属性。
当前XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<server>
<mbean code="org.jboss.varia.property.PropertyEditorManagerService"
name="jboss:type=Service,name=PropertyEditorManager">
</mbean>
<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss:type=Service,name=SystemProperties">
<attribute name="Properties">
my.project.property=This is the value of my property
</attribute>
</mbean>
</server>
我想在属性name =“Properties”中添加一个新属性。
结果:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<server>
<mbean code="org.jboss.varia.property.PropertyEditorManagerService"
name="jboss:type=Service,name=PropertyEditorManager">
</mbean>
<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss:type=Service,name=SystemProperties">
<attribute name="Properties">
my.project.property=This is the value of my property
my.project.anotherProperty=This is the value of my other property
</attribute>
</mbean>
</server>
感谢。
答案 0 :(得分:0)
这个简单的转换 - 覆盖身份规则:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pNewProp" select=
"'my.project.anotherProperty=This is the value of my other property '"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="attribute[@name='Properties']">
<attribute name="Properties">
<xsl:apply-templates/>
<xsl:value-of select="$pNewProp"/>
<xsl:text>
</xsl:text>
</attribute>
</xsl:template>
</xsl:stylesheet>
应用于提供的XML文档:
<server>
<mbean code="org.jboss.varia.property.PropertyEditorManagerService" name="jboss:type=Service,name=PropertyEditorManager"></mbean>
<mbean code="org.jboss.varia.property.SystemPropertiesService" name="jboss:type=Service,name=SystemProperties">
<attribute name="Properties">
my.project.property=This is the value of my property
</attribute>
</mbean>
</server>
生成想要的正确结果:
<server>
<mbean code="org.jboss.varia.property.PropertyEditorManagerService" name="jboss:type=Service,name=PropertyEditorManager"/>
<mbean code="org.jboss.varia.property.SystemPropertiesService" name="jboss:type=Service,name=SystemProperties">
<attribute name="Properties">
my.project.property=This is the value of my property
my.project.anotherProperty=This is the value of my other property
</attribute>
</mbean>
</server>