I'm new to XML and XSLT and have spent a bit of time on what should be a pretty simple search-and-replace case. I just can't seem to get the syntax correct.
The overall goal of this exercise is to replace the values of 'Y' and 'N' in element 'NewCustomer' with 'true' or 'false' respectively.
Here's my sample data.
<?xml version="1.0"?>
<CustomerList>
<Customer>
<CustomerID>1111</CustomerID>
<CompanyName>Sean Chai</CompanyName>
<City>New York</City>
<NewCustomer>N</NewCustomer>
</Customer>
<Customer>
<CustomerID>1112</CustomerID>
<CompanyName>Tom Johnston</CompanyName>
<City>Los Angeles</City>
<NewCustomer>N</NewCustomer>
</Customer>
<Customer>
<CustomerID>1113</CustomerID>
<CompanyName>Institute of Art</CompanyName>
<City>Chicago</City>
<NewCustomer>Y</NewCustomer>
</Customer>
</CustomerList>
Here's the transformation stylesheet.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Identity Template (applies to all nodes and will copy all nodes -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Customer">
<xsl:choose>
<xsl:when test="NewCustomer = 'Y'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:when test="NewCustomer = 'N'">
<xsl:text>false</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Here's my output.
<?xml version="1.0" encoding="utf-8" ?>
<CustomerList>false false true</CustomerList>
Here's what I want it to output.
<?xml version="1.0"?>
<CustomerList>
<Customer>
<CustomerID>1111</CustomerID>
<CompanyName>Sean Chai</CompanyName>
<City>New York</City>
<NewCustomer>false</NewCustomer>
</Customer>
<Customer>
<CustomerID>1112</CustomerID>
<CompanyName>Tom Johnston</CompanyName>
<City>Los Angeles</City>
<NewCustomer>false</NewCustomer>
</Customer>
<Customer>
<CustomerID>1113</CustomerID>
<CompanyName>Institute of Art</CompanyName>
<City>Chicago</City>
<NewCustomer>true</NewCustomer>
</Customer>
</CustomerList>
What am I missing and why? I see that if I leave out the clauses where I examine NewCustomer, the entire output gets output. However, choosing to output the properly changed values for NewCustomer results in only them displayed. Is there a reference to the previous template that I have to make in the second template?