我正在尝试使用 xsl.xml 使用来自 props 的值来重新设置一个可变的@env@
。
这是我目前的来源.xml
<projects>
<mbean code="org.jboss.naming.JNDIBindingServiceMgr" name="amfam.cbsconfig.jndi:name=cbsconfigJNDI">
<attribute name="BindingsConfig" serialDataType="jbxb">
<jndi:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd">
<jndi:binding name="books/category/config">
<java:properties xmlns:java="urn:jboss:java-properties"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
<java:property>
<java:key>url</java:key>
<java:value>@env@</java:value>
</java:property>
<java:property>
<java:key>url.port</java:key>
<java:value>@env@</java:value>
</java:property>
<java:property>
<java:key>category</java:key>
<java:value>@env@</java:value>
</java:property>
<java:property>
<java:key>sub-category</java:key>
<java:value>@env@</java:value>
</java:property>
<java:property>
<java:key>county</java:key>
<java:value>@env@</java:value>
</java:property>
<java:property>
<java:key>zip</java:key>
<java:value>@env@</java:value>
</java:property>
</java:properties>
</jndi:binding>
</jndi:bindings>
</attribute>
</mbean>
</projects>
我已经使用以下xsl代码尝试过这个:但不知何故,他们并没有从道具中提取任何价值.xml。
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:j="urn:jboss:jndi-binding-service:1.0"
version="2.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="no" indent="yes"/>
<xsl:key name="props" match="variable/*"
use="concat(../@id,'
',name(.))"/>
<xsl:template match="java:value" xmlns:java="urn:jboss:java-properties">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:variable name="id" select="../java:key"/>
<xsl:analyze-string select="." regex="@(.*?)@">
<xsl:matching-substring>
<xsl:value-of
select="key('props',concat($id,'
',regex-group(1)),
doc('props.xml'))"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
以下是从:props获得的值.xml
<?xml version="1.0" encoding="UTF-8"?>
<variables>
<variable id="url">
<env>abc.com</env>
</variable>
<variable id="url.port">
<env>1234</env>
</variable>
<variable id="category">
<env>books</env>
</variable>
<variable id="sub-category">
<env>ebooks</env>
</variable>
<variable id="county">
<env>zipling</env>
</variable>
<variable id="zip">
<env>00000</env>
</variable>
</variables>
是因为这条线吗...
<xsl:variable name="id" select="../@name"/>
您位于 java:value 元素上,但父元素没有 name 属性。看起来它是您需要在此处使用的java:key元素,因为这与props中的id相对应.xml。
<xsl:variable name="id" select="../java:key"/>