Switch through top level elements

I got a problem in xslt. My problem is, that I got a line in xml, which should be replaced by xsl. I want to replace a informatica file, which was generated by informatica itself.

At first, here is my xsl:

  <xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output
  method="xml"
  indent="yes"
  omit-xml-declaration="no"
  media-type="string"
  encoding="ISO-8859-1"
  doctype-system="deftable.dtd"
  /> 
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//AUTOEDIT2[@NAME='%%PARAM']">
        <xsl:choose>
            <xsl:when test="../JOB[@JOBNAME]='FILE_STUFF'">
                <AUTOEDIT2 NAME="%%PARAM" VALUE="*"/>
            </xsl:when>
            <xsl:when test="../JOB[@JOBNAME]='DATA_STUFF'">
                <AUTOEDIT2 NAME="%%PARAM" VALUE="*"/>
            </xsl:when>
            <xsl:when test="../JOB[@JOBNAME]='TANSFER_STUFF'">
                <AUTOEDIT2 NAME="%%PARAM" VALUE="*"/>
            </xsl:when>
            <xsl:otherwise>
                <AUTOEDIT2 NAME="%%PARAM" VALUE="20150910"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
  </xsl:stylesheet>

Now this is my xml, where the replacement should be done:

<SOMETREE>
    <JOB JOBNAME="FILE_STUFF">
        <AUTOEDIT2 NAME="%%PARAM" VALUE="not so important, should be overwritten"/>
    </JOB>
    <JOB JOBNAME="DATA_STUFF">
        <AUTOEDIT2 NAME="%%PARAM" VALUE="not so important, should be overwritten"/>
    </JOB>
    <JOB JOBNAME="TANSFER_STUFF">
        <AUTOEDIT2 NAME="%%PARAM" VALUE="not so important, should be overwritten"/>
    </JOB>
    <JOB JOBNAME="OTHER_STUFF">
        <AUTOEDIT2 NAME="%%PARAM" VALUE="not so important, should be overwritten"/>
    </JOB>
</SOMETREE>

So I want to overwrite the value “VALUE” in the AUTOEDIT2 field, related to the JOBNAME.

Thanks a lot for your time.

Best regards
Björn


Source: xml

Leave a Reply