Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xslt将文本添加到jboss properties-service.xml中_Xslt - Fatal编程技术网

xslt将文本添加到jboss properties-service.xml中

xslt将文本添加到jboss properties-service.xml中,xslt,Xslt,我想使用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=Pr

我想使用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>

my.project.property=这是我的属性的值
我想在attribute 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>

my.project.property=这是我的属性的值
my.project.anotherProperty=这是我的其他属性的值

谢谢。

这个简单的转换——覆盖身份规则:

<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>
    <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>
应用于提供的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>
    <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>

my.project.property=这是我的属性的值
生成所需的正确结果

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

my.project.property=这是我的属性的值
my.project.anotherProperty=这是我的其他属性的值

问得好,+1。请参阅我的答案,以获得完整、简短和简单的解决方案。