简体   繁体   中英

XSLT not transforming XML

In the XML shown below I want to replace the value of <machine>%%Process Archive.par-machine%%</machine> with 'jenkins'. I tried it to get it working with XSLT as can be seen below but it doesn't work. It did work with SED but that's not the DoD

What am I doing wrong in my XSLT code that it's not replacing the value?

XML Code:

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

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

You have a namespace in your source document which causes your match expression to fail. The namespace is the special xmlns attribute: xmlns="http://www.tibco.com/xmlns/ApplicationManagement" .

Have a look at this answer for an example of handling namespaces.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM