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/Sor t/@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:newSo rt(value); ">
<OPTION value="1">3 Month Reservations</OPTION>
<xsl:if test="$SortOrder[. = 1]">
<xsl:attribute name="SELECTED"></xsl:attr ibute>
</xsl:if>
<OPTION value="2">Property Name</OPTION>
<xsl:if test="$SortOrder[. = 2]">
<xsl:attribute name="SELECTED"></xsl:attr ibute>
</xsl:if>
<OPTION value="3">Property Id</OPTION>
<xsl:if test="$SortOrder[. = 3]">
<xsl:attribute name="SELECTED"></xsl:attr ibute>
</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:newSo rt(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?
<TR>
<TD align="center" width="82%" valign="middle">
<xsl:variable name="SortOrder" select="/Notifications/Sor
<B><font color="#FFFFFF" face="arial">Sort by </font></B>
<SELECT id="select1" style="FONT-SIZE: x-small; WIDTH: 150px" name="sortby" onchange="javascript:newSo
<OPTION value="1">3 Month Reservations</OPTION>
<xsl:if test="$SortOrder[. = 1]">
<xsl:attribute name="SELECTED"></xsl:attr
</xsl:if>
<OPTION value="2">Property Name</OPTION>
<xsl:if test="$SortOrder[. = 2]">
<xsl:attribute name="SELECTED"></xsl:attr
</xsl:if>
<OPTION value="3">Property Id</OPTION>
<xsl:if test="$SortOrder[. = 3]">
<xsl:attribute name="SELECTED"></xsl:attr
</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:newSo
<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?
You could also try:
<xsl:if test="number($SortOrder) = 2]">
>S'Plug<
<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.
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:attrib ute>
OR
<xsl:attribute name="SELECTED"><xsl:text> </xsl:text ></xsl:att ribute>
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.
<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</
OR
<xsl:attribute name="SELECTED"><xsl:text>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks much!
Sometimes I can't see for seeing with my own code.
Sometimes I can't see for seeing with my own code.
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</
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/So
>S'Plug<