Help with displaying HTML controls using XML/XSL

Good afternoon,

I am relatively new to XML and XSL and am trying to create an XML data island that is transformed using XSL and JavaScript.  In my practice pages, I get a recordset back from a database and I use server side code to generate the XML for it and write it to the web page.  Then I have an XSL file that has the table layout and such.  Then I use JavaScript to load and display it.

My dummy example is like this:
<XML id="XMLData">

<XML id="tableLayout" src="Table.xsl"></XML>

In my XSL file (Table.xsl) it is basic and looks like:
<xsl:template match="record">
<TD><xsl:value-of select="id" /></TD>
<TD><xsl:value-of select="name"/></TD>
etc. etc.

However, now that I have a conceptual grasp of it, it's time to put it to use and I am having problems.  I want to convert some current ASP code to this data island concept. However, I have no idea where to begin when a cell contains an HTML control, like a checkbox, with logic associated with it.  Let's pretend that the table column before "ID" would contain a checkbox.  For instance, this is an IF statement, which is contained in a Do Loop for each record in the recordset:

If displayStatus ="clearAll" or displayStatus=""Then%>

<input type="checkbox" name="checkbox" value="<%=tmpFileNo%>">

<input type="checkbox" name="checkbox" checked value="<%=tmpFileNo%>" strCanCheckOut="True">
<%End If%>

You see above that depending on the value of displayStatus, a checkbox is included in this cell with different properties set by server variables too.  I don't know how to account for this in the XML or XSL.  How would I generate the XML for the situation above and how would I account for this in the XSL?  

*Please be detailed as possible* because I am very new to this and am struggling a bit.  Thanks for your help.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you can use stylesheet parameter and conditional logic in XSL to achive it, i'll show you an example:

ok, let's provide parameter to XSLT, like displayStatus:

it can be done:
<xsl:param name="displayStatus"/>

then, you can refer to it like this: $displayStatus,

and now see complete stylesheet similiar to your ASP page:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:param name="displayStatus"/>
      <xsl:param name="fileNo"/>
      <xsl:template match="/">
            <!-- test value of dipslayStatus -->
                  <!-- if(displayStatus=clear) -->
                  <xsl:when test="$displayStatus='clear'">
                        <input type="checkbox" name="checkbox" value="$fileNo"/>
                  <!-- else -->
                        <input type="checkbox" name="checkbox" checked="true" value="$fileNo"/>

Feel free to ask.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Another way to handle conditional logic is with <xsl:if> and <xsl:attribute>.  This avoids repeating <input> elements multiple times
<input type='checkbox' name='checkbox{position()} value='{$fileNo}>
  <xsl:if test='$displayStatus!="clear"'>
     <xsl:attribute name='checked'>true</xsl:attribute>

Also note the {} characters.  They indictate to the XSL parser to evalute the XPATH expression (simalar to <%=..%> in ASP).  They were missing in dualsoul's example.

The code fragment above is using the position() function to get the position in a nodelist (i.e. part of a for-each loop).  It would produce output like this:
<input type='checkbox' name='checkbox1' value='1'/>
<input type='checkbox' name='checkbox2' value='1'/>
<input type='checkbox' name='checkbox3' value='1' checked='true'/>
<input type='checkbox' name='checkbox4' value='1'/>
<input type='checkbox' name='checkbox5' value='1'/>
>Also note the {} characters.

oh yeah, exactly - i've missed it, it's called AVT - attribute value template - this is shortcut for <xsl:attribute> when no any logic during processing needed.

like this :
<input value="{$fileNo}" /> is equas to <xsl:attribute name="value" select="$fileNo" />
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

dentyneAuthor Commented:
Good morning!  Thanks for the responses.  I just got into the office and I will definitely be looking over these soon.  I just wanted to post a comment to say thanks and that I was just getting around to reading them.  
dentyneAuthor Commented:
I am upping the point value 100 more points because I feel I might need a little bit more help.  I appreciate your time.  Thanks for both examples.  But how do the XSL parameters work?  Are they actually reading from the same parameter in the ASP page?  I did a small test creating the displayStatus variable in the ASP and setting it to "clear". But the logic in the XSLT didn't recognize this.  So I'm assuming I have to somehow populate the XSL parameter from my ASP page in the ASP do loop?  

The do loop I'm referring to in the ASP code is the loop that processes the recordset from the server.  The current, non-XML code, grabs the recordset and evaluates it row by row and based on some field values, populates variables like "displayStatus" and "fileNo".  Then the variables are evaluated at the HTML table row written with different values, such as a checkbox being unchecked or checked.

So in the new XML code, when I generate the XML, I am assuming I have to populate the XSL parameter that I created.  If I am correct in this assumption, how would I do this in my new XML generation loop? In the "new" XML code, here is what my XML generation looks like:

Response.Write("<xml id=""doclist"">" & vbCRLF)
Response.Write("<documents>" & vbCRLF)
Do While Not rs.EOF
   Response.Write("<record>" & vbCRLF)
   For x = 0 to rs.Fields.Count-1
      Response.Write("<" & lcase(rs.Fields(x).Name) & ">")
      Response.Write("</" & lcase(rs.Fields(x).Name) & ">" & vbCRLF)
   Response.Write("</record>" & vbCRLF)
Response.Write("</documents>" & vbCRLF)

The result would look like the XML in my original post. In the current, non-XML code, variables are populated in that Do Loop and HTML is written based on these values. So I assume this is where I would populate these XSL variables?

Thank you for your patience!
dentyneAuthor Commented:
Hmm do they not have assisted answer points anymore?  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.