I have a table that is populated from a SQL database. Most of the data entered will have an ABN which I can use to look up email and name. Some data doesn't have an ABN, and only has a UID. I don't want to have to display the UID in the table since its unnecessary 98% of the time, so I want to use an xsl:when to change the name field to the UID if there isn't a name.
Here is an example of the 2 cases in XML:
<?xml version="1.0" encoding="UTF-8"?>
<CourseData>
<row batchid="0" courseid="10101" createdon="04/03/2012 01:08PM" datecompleted="1:08 PM" datecompletedDateValue="1333483680000" lastupdatebyabn="999999" lastupdatebyuid="tsmith" lastupdateon="04/03/2012 01:08PM" num="2" respondentabn="999999" respondentemail="[email protected]" respondentid="1" respondentname="Thomas Smith" respondentuid="tsmith"/>
<row batchid="0" courseid="10101" createdon="04/03/2012 01:08PM" datecompleted="1:08 PM" datecompletedDateValue="1333483697000" lastupdatebyabn="" lastupdatebyuid="jsmith" lastupdateon="04/03/2012 01:08PM" num="3" respondentabn="" respondentemail="" respondentid="2" respondentname=" " respondentuid="jsmith"/>
</CourseData>
Here is the XSL I'm using, which obviously isn't working.
<xsl:choose>
<xsl:when test="row[@respondentabn='']">
<label datafield="@respondentuid"></label>
</xsl:when>
<xsl:otherwise>
<label datafield="@respondentname"></label>
</xsl:otherwise></xsl:choose></td>
How can I fix this?
Edit: So after talking to my boss, he said for one I'd need an loop in there for this to work right, but that I really shouldn't be doing this in the .xsl anyways. I modified my sql that is serving up the data to make that change for me, which in retrospect, I probably should have thought of in the first place.
<xsl:choose>
is invoked. The testrow[@respondentabn='']
is looking for the existence of arow
withrespondentabn
equal to a zero length string. If applied withCourseData
as the context node it is true because there exists one such row. – Jim Garrison