-
XML, XSLT and ASP.net
XML,XSLT and ASP.net
--------------------------------------------------------------------------------
Hi,
I need to render the XML document in a ASPX page, using XSLT. I am not able to handle multiple if conditions in the xslt file.
For example:
<choice value="Yes" name="yes" variable="choice">
<question type="lbl" value="Please select one or more sub-domains"></question>
<question type="checkbox" name="Perform Research and Design" ></question>
<question type="checkbox" name="Create and Manage Product Data" ></question>
<question type="checkbox" name="Manage Product Lifecycle"></question>
</choice>
<choice value="No"></choice>
I have rendered the choice as a dropdown in the XSLT. But I should place a condition, on the value 'Yes' in the dropdown, the checkbox should appear..
This is my XSLT file.
<xsl:choose>
<xsl:when test="$choice='Yes'">
<xsl:for-each select="question/choice/question">
<xsl:if test="@type='lbl'">
<asp:Label Cssclass="styletextsublabel1" runat="server"><xsl:value-of select="@value"></xsl:value-of></asp:Label>
</xsl:if>
</xsl:for-each>
<xsl:if test="@type='checkbox'">
<asp:Checkbox runat="server" Cssclass="stylepadding">
<xsl:for-each select="question">
<xsl:value-of select="@value" />
</xsl:for-each>
</asp:Checkbox>
</xsl:if>
</xsl:when>
</xsl:choose>
But it doesn't work..Can anybody help me out in resolving this..
-
Can anyone help in resolving this?
-
look at :- http://www.w3schools.com/xsl/xsl_choose.asp
use choose otherwise..
looking at your code below u have
$choice
but the XML you posted say choice is an attribute!!
<choice value="Yes" name="yes" variable="choice">
but u are calling $choice which seems to me as if
u have defined a vaiable or params..
Post your full XML
Patrick
<xsl:choose>
<xsl:when test="$choice='Yes'">
<xsl:for-each select="question/choice/question">
<xsl:if test="@type='lbl'">
<asp:Label Cssclass="styletextsublabel1" runat="server"><xsl:value-of select="@value"></xsl:value-of></asp:Label>
</xsl:if>
</xsl:for-each>
<xsl:if test="@type='checkbox'">
<asp:Checkbox runat="server" Cssclass="stylepadding">
<xsl:for-each select="question">
<xsl:value-of select="@value" />
</xsl:for-each>
</asp:Checkbox>
</xsl:if>
</xsl:when>
</xsl:choose>
-
XML,XSLT and ASP.net
Hi,
Thanks for the response. My Requirement is ,
I have an XML file which is like a survey. (ie) Question and Answers. Certain questions will appear based on the conditions.
<survey name="Scope">
<question type="label" name="Question1?" id="lblSQ1"></question>
<question type="dropdown" id="ddlSQ2">
<choice value="Yes"></choice>
<choice value="No"></choice>
</question>
<question type="label" name="Question2" id="lblSQ2">
</question>
<question type="label" name="Please select all that apply."></question>
<question type="label" name="Question 2A?" id="lblSQ2a">
</question>
<question type="dropdown" id="ddlSQ2a">
<choice value=""></choice>
<choice value="Yes" name="Yes" id="Yes">
<question type="lbl" name="Please select one or more sub-domains"></question>
<question type="checkbox" name="Perform Research and Design" ></question>
<question type="checkbox" name="Create and Manage Product Data" ></question>
<question type="checkbox" name="Manage Product Lifecycle"></question>
</choice>
<choice value="No"></choice>
</question>
Here it is.. I need to render the Question and the corresponding controls dynamicalay in ASPX page. For which i used the XSLT file.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="remove">
<xsl utput method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>
<xsl:template match="/">
<table cellSpacing="1" cellPadding="1" border="0">
<xsl:for-each select="//question">
<tr>
<td height="1px"></td>
</tr>
<tr>
<td valign="top" width="100%">
<xsl:choose>
<xsl:when test="choice='Yes'">
<xsl:for-each select="//question">
</xsl:for-each>
<xsl:if test="@type='checkbox'">
<asp:Checkbox runat="server" Cssclass="stylepadding">
<xsl:for-each select="survey/question/choice/question">
<xsl:if test="@type='lbl'">
<asp:Label Cssclass="styletextsublabel1" runat="server"><xsl:value-of select="@name"></xsl:value-of></asp:Label>
</xsl:if>
</xsl:for-each>
</asp:Checkbox>
</xsl:if>
</xsl:when>
</xsl:choose>
<xsl:if test="@type='label'">
<asp:Label Cssclass="styletextlabel1" runat="server"> <xsl:value-of select="@name" /></asp:Label>
</xsl:if>
<xsl:if test="@type='anchor'">
<a href="aa.com"><xsl:value-of select="@value" /></a>
</xsl:if>
</td>
</tr>
<tr>
<td class="stylepadding">
<xsl:if test="@type='text'">
<asp:TextBox id="{@name}" runat="server" />
</xsl:if>
<xsl:if test="@type='dropdown'">
<asp ropdownList Cssclass="styletextlabel1" runat="server" Autopostback="true" >
<xsl:for-each select="choice">
<asp:ListItem Value="{@value}"><xsl:value-of select="@value" /></asp:ListItem>
</xsl:for-each>
</asp ropdownList>
</xsl:if>
</td>
</tr>
<xsl:if test="@type='radio'">
<asp:RadioButtonList id="{@name}" runat="server">
<xsl:for-each select="choice">
<asp:ListItem Value="{@value}"><xsl:value-of select="@value" /></asp:ListItem>
</xsl:for-each>
</asp:RadioButtonList>
</xsl:if>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
(ie), I have rendered the questions with the choice 'Yes' and 'No' in a dropdown. Now i need to place a condition, when I choose the value 'Yes' in the dropdown, the other set of questions and choice in the XML file should appear, but this shouldn't happen on select of 'No' option in the dropdown.
Help me out in resolving this..
Thanks in advance..
TIG TIG
Similar Threads
-
By dhruba.bandopad in forum ASP.NET
Replies: 1
Last Post: 04-01-2006, 08:35 AM
-
Replies: 1
Last Post: 09-15-2005, 12:44 PM
-
By Greg Rothlander in forum ASP.NET
Replies: 1
Last Post: 08-30-2002, 08:43 AM
-
By ASPSmith Training in forum dotnet.announcements
Replies: 0
Last Post: 06-18-2002, 03:39 AM
-
By Colin Rogers in forum ASP.NET
Replies: 1
Last Post: 03-08-2001, 12:16 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|