I have been beating my head against my desk for days trying to sort this problem out...
Using javascript on the client I am taking an XML document created within SQL Server using FORXML and transforming it into an XHTML form via an XSLT file.
My issue is that I need to create a select list box of states and show the state represented in the data source XML file as selected. I have tried various means - primarily the document() function - to read in the XML file of states with no success. I have searched far and wide for examples of this, since I am sure many developers have had to to this and have also come up short.
Here is some abbreviated code:
USStates.xml
Code:
<usstates>
<state name="Florida" abbr="FL" />
<state name="California" abbr="CA" />
<state name="Ohio" abbr="OH" />
</usstates>
XML Generated from data source
Code:
<Lead ID="62215" Status="99" RepCSR="290 - John, Smith">
<LastUpdate>09-26-2003 20:36:56</LastUpdate>
<LastName>Doe</LastName>
<FirstName>John</FirstName>
<StreetAddress>123 ABC Street</StreetAddress>
<City>My Town</City>
<State>FL</State>
<ZipCode>12345</ZipCode>
<Phone>555-555-1212</Phone>
<EmailAddress>name@aol.com</EmailAddress>
</Lead>
FormatLeadEdit.xsl
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<!-- CONTAINER TEMPLATE -->
<xsl:template match="/Lead">
<xsl:call-template name="ContactInfo"/>
</xsl:template>
<!-- CONTACT INFORMATION TEMPLATE -->
<xsl:template name="ContactInfo">
<h1>Contact Information</h1>
<p>
<label>Name:</label>
<input type="text" name="FirstName" value="{FirstName}" class="FormElement" />
<input type="text" name="LastName" value="{LastName}" class="FormElement" />
</p>
<p>
<label>Street Address:</label>
<input type="text" name="StreetAddress" length="50" value="{StreetAddress}" class="FormElement" />
</p>
<p>
<input type="text" name="City" value="{City}" class="FormElement" />
<input type="text" name="State" value="{State}" class="FormElement" />
<input type="text" name="ZipCode" value="{ZipCode}" class="FormElement" />
</p>
</xsl:template>
</xsl:stylesheet>
Currently I am just loading the value of State into a text input box in FormatLeadEdit.xsl. I need to be able to create a select list out of the USState.xml file and use the value of State from the XML data source file as the selected index all within FormatLeadEdit.xsl.
This is such an easy thing to do in VBScript - ASP, but XML/XSLT has been a real struggle for me. Any help or links to resources would be greatly appreciated.