2011-09-08 6 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

이 간단한 변환 - 신원 규칙의 오버라이드 (override) :

<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 문서에 적용

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

:

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