2011-09-08 3 views
1

XSLTを使用してsystem-properties.xmlにプロパティを追加したいと思います。xslt jboss properties-service.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> 

私は、属性名= "プロパティ" の内側に新しいプロパティを追加します。

結果:

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

良い質問、+1。私の答えは完全で、簡単でシンプルな解決策を見てください。 –

答えて

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>&#xA;</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> 
関連する問題