Q:

XSL template priority

I have an XSL stylesheet that needs to be applied against two different XML inputs - a success response and an error response, and return valid XML for each.
Both input documents have the same general structure. I've tried approaching this using template priority, but this isn't behaving as I'd expect - the first template is always applying despite the priority being lower.
Why is this template applying in preference to the second one even for the success XML? If I remove the first template completely the 2nd one does apply correctly.
Is there a better approach I could take?
Success response:
<SOAP_Domain_Msg xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <Context>
        <Namespace xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
    </Context>
    <Header/>
    <Body>
        <GetCustomerResponse>
            <Title>Mr</Title>
            <FirstName>Test</FirstName>
            <Surname>Person</Surname>
        </GetCustomerResponse>
    </Body>
</SOAP_Domain_Msg>

Error response:
<SOAP_Domain_Msg xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <Context>
        <SOAP_Version>1.1</SOAP_Version>
        <Namespace xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"/>
    </Context>
    <Body>
        <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>2014-04-09T14:16:41: InternalFault</faultstring>
            <detail/>
        </soapenv:Fault>
    </Body>
</SOAP_Domain_Msg>

XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <xsl:template match="SOAP_Domain_Msg" priority="-1">
        <xsl:copy-of select="Body" />
  </xsl:template>
  <xsl:template match="Body/GetCustomerResponse" priority="0">
        <Applicants>
            <Applicant1>
                <xsl:if test="CustomerID != ''">
                    <Id>
                        <xsl:value-of select="CustomerID" />
                    </Id>
                </xsl:if>
                <xsl:if test="Title != ''">
                    <Title>
                        <xsl:value-of select="Title" />
                    </Title>
                </xsl:if>
                <xsl:if test="FirstName != ''">
                    <Forename1>
                        <xsl:value-of select="FirstName" />
                    </Forename1>
                </xsl:if>
                <xsl:if test="Surname != ''">
                    <Name>
                        <xsl:value-of select="Surname" />
                    </Name>
                </xsl:if>
            </Applicant1>
        </Applicants>
    </xsl:template>
</xsl:stylesheet>

A:

The priority is used to break ties when you have two different templates that could both apply to the same node.
With your stylesheet, processing will start with the document root node (/).  There is no explicit template matching this node, so the default behaviour will kick in, which is to apply-templates to all the children of this node.  So next the template matcher will try and find a template that can match the document element (/SOAP_Domain_Msg).  There is only one such template:
<xsl:template match="SOAP_Domain_Msg" priority="-1">
    <xsl:copy-of select="Body" />
</xsl:template>

so that template will fire.  Since this template does not include any apply-templates instructions, this is the end of the process and the final result will be a copy of the original Body element.
If you remove this template then you will instead get the default behaviour for SOAP_Domain_Msg, which is to apply-templates to children, and so on.  This will reach the point where it tries to apply templates to the GetCustomerResponse, at which point your other template will fire (in the meantime the processor will have applied the default templates to the Context, Namespace and Header elements as well, but since none of those contain any text content apart from whitespace they won't produce any noticeable output).
I would structure things slightly differently, starting with an identity template (which copies everything as-is unless you tell it otherwise) and then adding special cases as required.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

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

  <xsl:template match="/">
    <xsl:apply-templates select="SOAP_Domain_Msg/Body/*" />
  </xsl:template>

  <xsl:template match="GetCustomerResponse">
    <Applicants>
      <Applicant1>
        <xsl:apply-templates select="CustomerID | Title | FirstName | Surname" />
      </Applicant1>
    </Applicants>
  </xsl:template>

  <xsl:template match="CustomerID">
    <Id><xsl:apply-templates /></Id>
  </xsl:template>

  <xsl:template match="FirstName">
    <Forename1><xsl:apply-templates /></Forename1>
  </xsl:template>

  <xsl:template match="Surname">
    <Name><xsl:apply-templates /></Name>
  </xsl:template>

</xsl:stylesheet>

There are no specific templates necessary for the things you don't want to change (the fault case, and the Title element in the success case).

