Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 14th, 2009, 10:03 AM
Authorized User
 
Join Date: Aug 2009
Location: India
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amitranjan286 Send a message via Yahoo to amitranjan286
Unhappy using Dropdown in XSLT

Hi,
I am a noobie to xslt. I need to bind a my xml contents to a dropdown.
Let me explain in detail.

xml:
<CarrierEnrollmentForm>
<Coverage>
<RelationshipDaughter>false</RelationshipDaughter>
<RelationshipDependent>false</RelationshipDependent>
<RelationshipDomesticPartner>false</RelationshipDomesticPartner>
<RelationshipHusbant>false</RelationshipHusbant>
<RelationshipSelf>false</RelationshipSelf>
<RelationshipSon>false</RelationshipSon>
<RelationshipSpouse>false</RelationshipSpouse>
<RelationshipWife>false</RelationshipWife>
</Coverage>
</CarrierEnrollmentForm>

Below is my html dropdown combo.
<Select id = "xyz" name="xyz">
<option> Daughter</option>
<option> Dependent</option>
<option> Domestic Partner</option>
<option> Son</option>
<option> Wife</option>
<option> Husband</option>
<option> spouse</option>
</Select>

I need to such a maping that If I select Son from UI then it will give me true or something so that i can set true to <RelationShipSon>true</RelationshipSon> or i can determine that Son is selected. Similary if I select Spouse then it will yield the respective value of spouse and so on.

So please help me in achieving this, ASAP.
Reply With Quote
  #2 (permalink)  
Old August 14th, 2009, 10:14 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

XSLT can generate HTML as a transformation result but there is no binding between XML input and the transformation result. You would need to write some code outside of XSLT to establish such a binding. How you do that exactly depends very much on the server-side framework (e.g. ASP.NET, JSP) you use to run the XSLT transformation.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #3 (permalink)  
Old August 14th, 2009, 10:27 AM
Authorized User
 
Join Date: Aug 2009
Location: India
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amitranjan286 Send a message via Yahoo to amitranjan286
Default

Binding in sense, i need to map Dropdown with xml, for example what i am using right now is

<select name="CEF_Coverage_PrimaryBeneficiary_Relationship Dependent_ddl" id="CEF_Coverage_PrimaryBeneficiary_RelationshipDe pendent_ddl">
<xsl:if test="/doc:CarrierEnrollmentForm/doc:Coverage/doc:PrimaryBeneficiary/doc:RelationshipDependent = 'false'">
<option Value="Husband">Husband</option>
<option Value="Wife">Wife</option>
<option Value="Son">Son</option>
<option Value="Daughter">Daughter</option>
<option Value="Spouse">Spouse</option>
<option Value="Dependent">Dependent</option>
<option Value="Domestic">Domestic Partner</option>
</xsl:if>
</select>
Reply With Quote
  #4 (permalink)  
Old August 14th, 2009, 10:29 AM
Authorized User
 
Join Date: Aug 2009
Location: India
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amitranjan286 Send a message via Yahoo to amitranjan286
Default

But the above is for temporary use or say just a sample to display the dropdown on the form with the respective values, and is not working.
Reply With Quote
  #5 (permalink)  
Old August 14th, 2009, 10:34 AM
Authorized User
 
Join Date: Aug 2009
Location: India
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amitranjan286 Send a message via Yahoo to amitranjan286
Default

Also i the above sample of xml in my code is just a small part of entire xml. <Coverage></Coverage> has more than 100 nodes inside. So i cant iterate it to place all the nodes to dropdown automatically.
So i need some efficient way to do this.
Reply With Quote
  #6 (permalink)  
Old August 14th, 2009, 10:46 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Generating your HTML dropdown from your XML is straightforward, and if that's what you are having trouble with, we can help. But you seem to want to do more than that - perhaps (?) you are hoping to build a system in which the user can select from the dropdown, and this causes some kind of update to the XML file? You can build such a system, but it needs more than XSLT: it typically needs some software on the server that accepts an HTTP request from the browser and responds to it with a file update. It's hard to help you without knowing more about your requirement and about your application architecture.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #7 (permalink)  
Old August 14th, 2009, 10:50 AM
Authorized User
 
Join Date: Aug 2009
Location: India
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amitranjan286 Send a message via Yahoo to amitranjan286
Default

You are true. I need to update my XML on the fly and i have cs code for parsing rendered html file over the browser but i am stucked with, using dropdown in xslt... please help
Reply With Quote
  #8 (permalink)  
Old August 17th, 2009, 08:40 AM
Authorized User
 
Join Date: Aug 2009
Location: India
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amitranjan286 Send a message via Yahoo to amitranjan286
Default

Hi guys, nobody here to help me...??????
Reply With Quote
  #9 (permalink)  
Old August 17th, 2009, 08:44 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, we tried to help you. We asked you questions about your application architecture, because this isn't primarily an XSLT problem. But you didn't answer.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #10 (permalink)  
Old August 17th, 2009, 09:24 AM
Authorized User
 
Join Date: Aug 2009
Location: India
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to amitranjan286 Send a message via Yahoo to amitranjan286
Default

Sorry for that... I explained but , i think i was not that much clear to you. Let me explain it in detail;

My application has an xml file, generated by some webservice. generated xml is below:
xml:
<CarrierEnrollmentForm>
<Coverage>
<RelationshipDaughter>false</RelationshipDaughter>
<RelationshipDependent>false</RelationshipDependent>
<RelationshipDomesticPartner>false</RelationshipDomesticPartner>
<RelationshipHusbant>false</RelationshipHusbant>
<RelationshipSelf>false</RelationshipSelf>
<RelationshipSon>false</RelationshipSon>
<RelationshipSpouse>false</RelationshipSpouse>
<RelationshipWife>false</RelationshipWife>
</Coverage>
</CarrierEnrollmentForm>

Below is my html dropdown combo mapped , that i placed in aspx file.
Code:
 <select name="CEF_Coverage_Contingent_RelationshipDependent_ddl" id="CEF_Coverage_Contingent_RelationshipDependent_ddl">
                                  <xsl:if test="/doc:CarrierEnrollmentForm/doc:Coverage/doc:Contingent/doc:RelationshipDependent = 'false'">
                                    <option Value="Husband">Husband</option>
                                    <option Value="Wife">Wife</option>
                                    <option Value="Son">Son</option>
                                    <option Value="Daughter">Daughter</option>
                                    <option Value="Spouse">Spouse</option>
                                    <option Value="Dependent">Dependent</option>
                                    <option Value="Domestic">Domestic Partner</option>

                                  </xsl:if>
                                </select>
I need to such a maping that If I select Son from UI then it will give me true or something so that i can set true to <RelationShipSon>true</RelationshipSon> in xml or i can determine that Son is selected. Similary if I select Spouse then it will yield the respective value of spouse and so on.

For example
For toggling Male and Female i have used:

Code:
  <input type="radio" value="true"  name="CEF_Employee_************_radiobutton" id="CEF_Employee_************_radiobutton" >
                                        <xsl:choose>
                                          <xsl:when test="/doc:CarrierEnrollmentForm/doc:Employee/doc:************='true'">
                                            <xsl:attribute name="checked">1</xsl:attribute>
                                          </xsl:when>
                                          <xsl:otherwise>
                                          </xsl:otherwise>
                                        </xsl:choose>
                                      </input>
                                      <label for="" class="fontnormal">Male</label>
                                      <br></br>
                                      <input type="radio" value="false"   name="CEF_Employee_************_radiobutton" id="CEF_Employee_************_radiobutton">
                                        <xsl:choose>
                                          <xsl:when test="/doc:CarrierEnrollmentForm/doc:Employee/doc:************='false'">
                                            <xsl:attribute name="checked">1</xsl:attribute>
                                          </xsl:when>
                                          <xsl:otherwise>
                                          </xsl:otherwise>
                                        </xsl:choose>
                                      </input>
                                      <label for="" class="fontnormal">Female</label>
While parsing in CS i am using Request.Form[i] == true|false for getting radiobutton output.
CS Code
Code:
  private void ParseHTMLControlValues()
    {
        XElement PrimaryXMLElement = XElement.Parse(_presenter.GetCarrierFormData(empID));
        XNamespace xmlNameSpace = "http://schemas.datacontract.org/2004/07/BMES.WFC.DataContracts.CarrierFormData2";

        for (int i = 0; i < Request.Form.Count; i++)
        {
            try
            {
                if (!Request.Form.Keys[i].StartsWith("CEF_")) continue;
                string[] strArray = Request.Form.Keys[i].Replace("CEF_", "").Split('_');
                XElement SecondaryXMLElement = PrimaryXMLElement;
                foreach (string item in strArray)
                {
                    //If the following conditions are true, remove the extra appended text from control name/id
                    //and then parse the form and set value to XML else let values remain as it is.
                    if ((item.ToLower().Trim() != "checkbox") &&
                       (item.ToLower().Trim() != "radiobutton") &&

                       (item.ToLower().Trim() != "ddl"))))
                    {
                        SecondaryXMLElement = SecondaryXMLElement.Element(xmlNameSpace + item);
                    }
                }
                //Query for checkbox control over entire form whose ID/Name ends with checkbox.
                //Gets true/false from the form control state and sets true/false to the XML.

                if ((Request.Form.Keys[i].ToLower()).EndsWith("checkbox"))
                {
                    if (Request.Form[i].ToString().ToLower() == ",on")
                    {
                            SecondaryXMLElement.SetValue("true");
                    }
                    else
                    {
                        SecondaryXMLElement.SetValue("false");
                    }                    
                }
                //Query for radiobutton control over entire form whose ID/Name ends with radiobutton.
                //Gets true/false from the form control state and sets true/false to the XML.
                else if ((Request.Form.Keys[i].ToLower()).EndsWith("radiobutton"))
                {

                    if (Request.Form[i].ToString() == "true")
                    {
                        SecondaryXMLElement.SetValue("true");
                    }
                    else
                    {
                        SecondaryXMLElement.SetValue("false");
                    }
                }
                /**********************************************************************
             *          BCBS Enrollment Form Special Handling Section              *               
             **********************************************************************/
                // For setting relationship of Primary Benificiary. Search for Coverage node under the XML then 
                // iterated that node for Primary benificiary/Relationship tag and if the tag matches with dropdown value,
                //it sets the respective value in xml to true.
                else if ((Page.Request.Form.Keys[i].ToLower()).EndsWith("bcbspbddl"))
                {
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.LoadXml(PrimaryXMLElement.ToString());
                    XmlNodeList xmlnode = xmldoc.GetElementsByTagName("Coverage");
                    //XmlElement root = xmldoc.DocumentElement;
                    for (int intCtr = 0; intCtr < xmlnode.Count; intCtr++)
                    {
                        XmlNodeList XChildNodes = xmlnode[intCtr].ChildNodes;
                        for (int ChildCtr = 0; ChildCtr < XChildNodes.Count; ChildCtr++)
                        {
                            if (XChildNodes[ChildCtr].Name.Contains("PrimaryBeneficiary"))
                            {
                                XmlNodeList SubChildNodes = XChildNodes[ChildCtr].ChildNodes;
                                for (int SubChildCtr = 0; SubChildCtr < SubChildNodes.Count; SubChildCtr++)
                                {
                                    if (SubChildNodes[SubChildCtr].Name.Contains("Relationship"))
                                    {
                                        if (SubChildNodes[SubChildCtr].Name.Contains(Page.Request.Form[i].ToString()))
                                        {
                                            XmlNode innerSubChildNode = SubChildNodes[SubChildCtr];
                                            innerSubChildNode.InnerXml = "true";
                                        }
                                        else
                                        {
                                            XmlNode innerSubChildNode = SubChildNodes[SubChildCtr];
                                            innerSubChildNode.InnerXml = "false";
                                        }
                                    }
                                }
                            }
                        }
                        PrimaryXMLElement = XElement.Parse(xmldoc.InnerXml);
                    }
                }
                // For setting relationship of Contingent. Search for Coverage node under the XML then 
                // iterated that node for Relationship tag and if the tag matches with dropdown value,
                //it sets the respective value in xml to true.
                else if ((Page.Request.Form.Keys[i].ToLower()).EndsWith("bcbscddl"))
                {
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.LoadXml(PrimaryXMLElement.ToString());
                    XmlNodeList xmlnode = xmldoc.GetElementsByTagName("Coverage");
                    //XmlElement root = xmldoc.DocumentElement;
                    for (int intCtr = 0; intCtr < xmlnode.Count; intCtr++)
                    {
                        XmlNodeList XChildNodes = xmlnode[intCtr].ChildNodes;
                        for (int ChildCtr = 0; ChildCtr < XChildNodes.Count; ChildCtr++)
                        {
                            if (XChildNodes[ChildCtr].Name.Contains("Contingent"))
                            {
                                XmlNodeList SubChildNodes = XChildNodes[ChildCtr].ChildNodes;
                                for (int SubChildCtr = 0; SubChildCtr < SubChildNodes.Count; SubChildCtr++)
                                {
                                    if (SubChildNodes[SubChildCtr].Name.Contains("Relationship"))
                                    {
                                        if (SubChildNodes[SubChildCtr].Name.Contains(Page.Request.Form[i].ToString()))
                                        {
                                            XmlNode innerSubChildNode = SubChildNodes[SubChildCtr];
                                            innerSubChildNode.InnerXml = "true";
                                        }
                                        else
                                        {
                                            XmlNode innerSubChildNode = SubChildNodes[SubChildCtr];
                                            innerSubChildNode.InnerXml = "false";
                                        }
                                    }
                                }
                            }
                        }
                        PrimaryXMLElement = XElement.Parse(xmldoc.InnerXml);
                    }
                }                else
                {
                    string[] str = Request.Form[i].Split(',');
                    SecondaryXMLElement.SetValue(str[0]);
                }
            }
            catch(Exception ex)
            {
                throw ex;

            }

        }
        Session["updatedXML"] = null;
        Session["updatedXML"] = PrimaryXMLElement.ToString();
        //_presenter.SetCarrierFormData(PrimaryXMLElement.ToString(), empID);
        Response.Redirect("CarrierForm.aspx?Carrier=" + Request.QueryString["Carrier"].ToString() + "&EmpID=" + empID + "&Mode=Disabled");

    }
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Another question about generating XSLT with XSLT danblick XSLT 2 July 16th, 2009 08:40 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM



All times are GMT -4. The time now is 10:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.