@donttryathome,
The entirety of the XML tree is being returned because you are missing the following element:
Code:
<xsl:template match="/">
</xsl:template>
There are several ways you can complete your XML package. The following XML package contains two examples.
Method A: Assign the "Country" value to a param, and later retrieve it in the "root" template element.
Method B: Create a separate template element for the "Address" node, where the child "Country" can be retrieved.
Code:
<?xml version="1.0" standalone="yes" ?>
<package version="2.1" displayname="Featured Products" debug="false">
<query name="Shipping" rowElementName="Address" >
<sql>
<![CDATA[
SELECT A.Country FROM Address A WITH(NOLOCK)
LEFT JOIN Customer C WITH(NOLOCK) ON C.ShippingAddressID = A.AddressID
WHERE C.CustomerID = @customerid
]]>
</sql>
<queryparam paramname="@customerid" paramtype="system" requestparamname="CustomerID" sqlDataType="int" defvalue="0" validationpattern="" />
</query>
<PackageTransform>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf" >
<xsl:output method="html" omit-xml-declaration="yes" />
<!--Method A-->
<xsl:param name="ShipToCountry">
<xsl:value-of select="/root/Shipping/Address/Country" />
</xsl:param>
<!--End Method A-->
<xsl:template match="/" >
<!--Method A-->
Customer Shipping Country: <xsl:value-of select="$ShipToCountry" />
<xsl:if test="$ShipToCountry = 'Canada'">
<br/>
This customer has a Canadian shipping address.
</xsl:if>
<!--End Method A-->
<!--Method B-->
<xsl:apply-templates select="/root/Shipping/Address"></xsl:apply-templates>
<!--End Method B-->
</xsl:template>
<!--Method B-->
<xsl:template match="Address">
<xsl:param name="ShipCountry" select="Country"></xsl:param>
Customer Shipping Country: <xsl:value-of select="$ShipCountry" />
<xsl:if test="$ShipCountry = 'Canada'">
<br/>
This customer has a Canadian shipping address.
</xsl:if>
</xsl:template>
<!--End Method B-->
</xsl:stylesheet>
</PackageTransform>
</package>
You will also notice that the XML package contains the "if" element, which tests if "Country" is equal to "Canada" before displaying its child contents. It is important to note that this test is case sensitive. If casing is not a concern, it may be beneficial to convert casing before comparing values. This is especially valuable for user entered values.
For reference, the following example can be used to convert all the characters in a string to lower or upper case.
Code:
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:template match="/">
<xsl:value-of select="translate(doc, $smallcase, $uppercase)" />
</xsl:template>
In my opinion, it is also good practice to keep the query "name" and "rowElementName" different. Mainly to avoid confusion when referencing a specific node.
Code:
<query name="Shipping" rowElementName="Address" >
Don't hesitate to ask any questions.
Robert