<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="transactions">
<Transactions>
<giftShop number="1">
<Date date="01/11/2019">
<xsl:apply-templates select="transaction" mode = "a1"/>
</Date>
<Date date="02/11/2019">
<xsl:apply-templates select="transaction" mode = "a2"/>
</Date>
<Date date="03/11/2019">
<xsl:apply-templates select="transaction" mode = "a3"/>
</Date>
</giftShop>
<giftShop number="2">
<Date date="01/11/2019">
<xsl:apply-templates select="transaction" mode = "a4"/>
</Date>
<Date date="02/11/2019">
<xsl:apply-templates select="transaction" mode = "a5"/>
</Date>
<Date date="03/11/2019">
<xsl:apply-templates select="transaction" mode = "a6"/>
</Date>
</giftShop>
<giftShop number="3">
<Date date="01/11/2019">
<xsl:apply-templates select="transaction" mode = "a7"/>
</Date>
<Date date="02/11/2019">
<xsl:apply-templates select="transaction" mode = "a8"/>
</Date>
<Date date="03/11/2019">
<xsl:apply-templates select="transaction" mode = "a9"/>
</Date>
</giftShop>
</Transactions>
</xsl:template>
<xsl:template match="transaction" mode="a1">
<xsl:variable name="addIn" select="document('retail_customers.xml')"/>
<xsl:variable name="customerID" select="customerID"/>
<xsl:choose>
<xsl:when test="giftShop='1' and transaction_date='01/11/2019'">
<Transaction>
<accountnumber> <xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text></accountnumber>
<xsl:copy-of select="transactionID"/>
<xsl:copy-of select="value"/>
<xsl:copy-of select="customerID"/>
<xsl:for-each select="$addIn/customers/customer">
<xsl:if test="customerID=$customerID">
<xsl:copy-of select="prefix"/>
<xsl:copy-of select="lastName"/>
<xsl:copy-of select="givenName"/>
<xsl:copy-of select="addressID"/>
</xsl:if>
</xsl:for-each>
</Transaction>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>