开发者

xslt add text into jboss properties-service.xml

I would like to add property in system-properties.xml by using XSLT.

Current XML file:

<?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>

I want to add a new property inside attribute name="Properties".

RESULT:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<server>
  <mbean code="org.jboss.varia.property.PropertyEditorManagerService"
         name="jboss:type=Servi开发者_StackOverflowce,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>

Thanks.


This simple transformation -- overriding of the identity rule:

<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>&#xA;</xsl:text>
    </attribute>
 </xsl:template>
</xsl:stylesheet>

when applied on the provided XML document:

<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>

produces the wanted, correct result:

<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>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜