XSLT检查父代码值并替换子节点

时间:2017-09-22 10:00:48

标签: xml xslt

我有以下xml

<job-steps>
     <job-step xsi:type="ftp-outbound-job-step">
                <description>JOB DETAILS</description>
                <job-step-id>JOB1</job-step-id>
                  <configuration>
                    <job-step-params xsi:type="ftp-outbound-job-step-params">
                        <username>USER1</username>
                         <file-path>TOBEREPLPACED</file-path>
                    </job-step-params>      
                </configuration>
    </job-step>
    <job-step xsi:type="ftp-outbound-job-step">
                <description>JOB DETAILS</description>
                <job-step-id>JOB2</job-step-id>
                  <configuration>
                    <job-step-params xsi:type="ftp-outbound-job-step-params">
                        <username>USER1</username>
                         <file-path>NOTTOBEREPLACED</file-path>`enter code here`
                    </job-step-params>      
                </configuration>
     </job-step>
</job-steps>

如何修改xslt,以便只更改<file-path>中的job-step-id=JOB1值,而不是JOB2

1 个答案:

答案 0 :(得分:0)

我猜你想做点什么:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

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

<xsl:template match="file-path[ancestor::job-step/job-step-id='JOB1']">
    <xsl:copy>new path here</xsl:copy>
</xsl:template>

</xsl:stylesheet>