Link to home
Start Free TrialLog in
Avatar of robad
robad

asked on

xsl:attribute tag not working

This is driving me crazy ...  Here is a fragement of xsl from an xsl style sheet.

         <TR>
              <TD align="center" width="82%" valign="middle">
                   <xsl:variable name="SortOrder" select="/Notifications/Sort/@Order"/>
                   <B><font color="#FFFFFF" face="arial">Sort by </font></B>
                   <SELECT id="select1" style="FONT-SIZE: x-small; WIDTH: 150px" name="sortby" onchange="javascript:newSort(value);">
                         <OPTION value="1">3 Month Reservations</OPTION>
                              <xsl:if test="$SortOrder[. = 1]">
                                   <xsl:attribute name="SELECTED"></xsl:attribute>          
                              </xsl:if>
                         <OPTION value="2">Property Name</OPTION>
                              <xsl:if test="$SortOrder[. = 2]">
                                   <xsl:attribute name="SELECTED"></xsl:attribute>          
                              </xsl:if>                        
                         <OPTION value="3">Property Id</OPTION>
                              <xsl:if test="$SortOrder[. = 3]">
                                   <xsl:attribute name="SELECTED"></xsl:attribute>          
                              </xsl:if>                        
                    </SELECT>
                              <xsl:if test="$SortOrder[. = 2]">
                                   <xsl:text>TEST WAS PASSED</xsl:text>
                              </xsl:if>
               </TD>
         </TR>

All I want to do is to set the SELECTED attribute.

Here is the HTML I get:

<TR>
<TD align="center" width="82%" valign="middle"><B><font color="#FFFFFF" face="arial">Sort by </font></B><SELECT id="select1" style="FONT-SIZE: x-small; WIDTH: 150px" name="sortby" onchange="javascript:newSort(value);"><OPTION value="1">3 Month Reservations</OPTION>
<OPTION value="2">Property Name</OPTION>
<OPTION value="3">Property Id</OPTION></SELECT>TEST WAS PASSED</TD>
</TR>

Please note that the last text string indicates that I am picking up the desired node value and testing it properly.  The only issue is that the SELECTED attribute is, never-the-less NOT set.

Can anyone give me a clue as to what might be going on?
Avatar of sparkplug
sparkplug

Robad,

Although I don't think that this is your problem, you should give the selected attribute a value. In XHTML this should be the name of the attribute.

e.g.
<xsl:attribute name="selected">selected</xsl:attribute>

Apart from that I can't see any problem with the XSL code. I would however need to see the XML that you are tranforming. What does 'select="/Notifications/Sort/@Order"/' actually match? If this is not 1, 2 or 3, then you will not get the select attribute in the output.

>S'Plug<

You could also try:
<xsl:if test="number($SortOrder) = 2]">

>S'Plug<
As sparky said, give the attribute a value, and ensure that the xsl:output method is set to html. Then the tree flattener will produce the correct HTML.
Avatar of robad

ASKER

I should clarify that the following (from my original question) is debugging code to make sure that the xsl:if test = is properly structured:
                             <xsl:if test="$SortOrder[. = 2]">
                                  <xsl:text>TEST WAS PASSED</xsl:text>
                             </xsl:if>

When the source xml contains <Sort Order="2"/>, the html output contains

<OPTION value="3">Property Id</OPTION></SELECT>TEST WAS PASSED</TD>

This tells me that the problem is NOT with the if test.  Also, I have already tried giving the SELECTED attribute a value along the lines of

<xsl:attribute name="SELECTED">SELECTED</xsl:attribute>    

OR

<xsl:attribute name="SELECTED"><xsl:text></xsl:text></xsl:attribute>

Neither makes a difference.  Further, I am using Microsoft XSL 4.0 which creates an attribute

SELECTED = ""

with no value assigned in a different style sheet.    
ASKER CERTIFIED SOLUTION
Avatar of sparkplug
sparkplug

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of robad

ASKER

Thanks much!  

Sometimes I can't see for seeing with my own code.