【问题标题】:XSLT not transforming XMLXSLT 不转换 XML
【发布时间】:2015-12-01 09:03:45
【问题描述】:

在下面显示的 XML 中,我想将 <machine>%%Process Archive.par-machine%%</machine> 的值替换为“jenkins”。我尝试让它与 XSLT 一起工作,如下所示,但它不起作用。它确实适用于 SED,但那不是 D.o.D.

我在 XSLT 代码中做错了什么,它没有替换值?

XML 代码:

<?xml version="1.0" encoding="UTF-8"?>

<application xmlns="http://www.tibco.com/xmlns/ApplicationManagement" name="HelloWorld">
    <description/>
    <contact/>
    <NVPairs name="Global Variables">
        <NameValuePair>
            <name>DirLedger</name>
            <value>.</value>
        </NameValuePair>
        <NameValuePair>
            <name>DirTrace</name>
            <value>.</value>
        </NameValuePair>
        <NameValuePair>
            <name>HawkEnabled</name>
            <value>false</value>
        </NameValuePair>
        <NameValuePair>
            <name>JmsProviderUrl</name>
            <value>tcp://localhost:7222</value>
        </NameValuePair>
        <NameValuePair>
            <name>JmsSslProviderUrl</name>
            <value>ssl://localhost:7243</value>
        </NameValuePair>
        <NameValuePair>
            <name>RemoteRvDaemon</name>
            <value/>
        </NameValuePair>
        <NameValuePair>
            <name>RvDaemon</name>
            <value>tcp:7500</value>
        </NameValuePair>
        <NameValuePair>
            <name>RvNetwork</name>
            <value/>
        </NameValuePair>
        <NameValuePair>
            <name>RvService</name>
            <value>7500</value>
        </NameValuePair>
        <NameValuePair>
            <name>RvaHost</name>
            <value>localhost</value>
        </NameValuePair>
        <NameValuePair>
            <name>RvaPort</name>
            <value>7600</value>
        </NameValuePair>
        <NameValuePair>
            <name>TIBHawkDaemon</name>
            <value>tcp:7474</value>
        </NameValuePair>
        <NameValuePair>
            <name>TIBHawkNetwork</name>
            <value/>
        </NameValuePair>
        <NameValuePair>
            <name>TIBHawkService</name>
            <value>7474</value>
        </NameValuePair>
    </NVPairs>
    <repoInstances selected="rv">
        <httpRepoInstance>
            <timeout>600</timeout>
            <url/>
        </httpRepoInstance>
        <rvRepoInstance>
            <timeout>600</timeout>
            <discoveryTimout>10</discoveryTimout>
            <daemon>tcp:7500</daemon>
        </rvRepoInstance>
        <localRepoInstance>
            <encoding>ISO8859-1</encoding>
        </localRepoInstance>
    </repoInstances>
    <services>
        <bw name="Process Archive.par">
            <enabled>true</enabled>
            <bindings>
                <binding name="">
                    <machine>%%Process Archive.par-machine%%</machine>
                    <product>
                        <type>bwengine</type>
                        <version/>
                        <location/>
                    </product>
                    <description/>
                    <contact/>
                    <shutdown>
                        <checkpoint>false</checkpoint>
                        <timeout>0</timeout>
                    </shutdown>
                </binding>
            </bindings>
            <NVPairs name="Adapter SDK Properties">
                <NameValuePair>
                    <name>Trace.Task.*</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>EnableMemorySavingMode</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.engine.enableJobRecovery</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.engine.autoCheckpointRestart</name>
                    <value>true</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.engine.jobstats.enable</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>log.file.encoding</name>
                    <value/>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.engine.emaEnabled</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.container.service</name>
                    <value/>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.container.service.rmi.port</name>
                    <value>9995</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.platform.services.retreiveresources.Enabled</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.platform.services.retreiveresources.Hostname</name>
                    <value>localhost</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.platform.services.retreiveresources.Httpport</name>
                    <value>8010</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.platform.services.retreiveresources.defaultEncoding</name>
                    <value>ISO8859_1</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.platform.services.retreiveresources.enableLookups</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.platform.services.retreiveresources.isSecure</name>
                    <value>false</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.platform.services.retreiveresources.identity</name>
                    <value>/Identity_HTTPConnection.id</value>
                </NameValuePair>
                <NameValuePair>
                    <name>bw.log4j.configuration</name>
                    <value/>
                </NameValuePair>
            </NVPairs>
            <failureCount>0</failureCount>
            <failureInterval>0</failureInterval>
            <bwprocesses>
                <bwprocess name="Processes/HelloWorld.process">
                    <starter>HTTP Receiver</starter>
                    <enabled>true</enabled>
                    <maxJob>0</maxJob>
                    <activation>true</activation>
                    <flowLimit>0</flowLimit>
                </bwprocess>
            </bwprocesses>
            <isFt>false</isFt>
        </bw>
    </services>
</application>

XSLT 代码:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="/application/services/bw/bindings/binding/machine/text()">jenkins</xsl:template>

</xsl:stylesheet>

【问题讨论】:

  • 搜索“XSLT 默认命名空间”,您会发现大约有五千人犯了同样的错误。

标签: xml xslt xpath replace transform


【解决方案1】:

您的源文档中有一个命名空间,导致匹配表达式失败。命名空间是特殊的xmlns 属性:xmlns="http://www.tibco.com/xmlns/ApplicationManagement"

查看this answer 以获取处理命名空间的示例。

【讨论】:

    猜你喜欢
    • 2019-10-06
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多