RE: HTML characters being converted

Subject: RE: HTML characters being converted
From: David Lamy <DLamy@xxxxxxxxxxx>
Date: Fri, 3 Dec 1999 11:23:10 -0700
Thanks for the responses.  Here's some XML/XSL code.  Please be gentle..
I'm suddenly feeling much more self-conscious about my XSL ;-).

XML: (important elements here are the CheckBoxGroup and the CheckBox)
		<CheckBoxGroup numberOfColumns="2">
			<CheckBox checked="true">
				<CheckBoxValueDataSource>
					<TextData>1</TextData>
				</CheckBoxValueDataSource>
				<CheckBoxDisplayDataSource>
					<TextData>checked by
default</TextData>
				</CheckBoxDisplayDataSource>
			</CheckBox>
			<CheckBox>
				<CheckBoxValueDataSource>
					<TextData>2</TextData>
				</CheckBoxValueDataSource>
				<CheckBoxDisplayDataSource>
					<TextData>another choice to
select</TextData>
				</CheckBoxDisplayDataSource>
			</CheckBox>
			<CheckBox>
				<CheckBoxValueDataSource>
					<TextData>3</TextData>
				</CheckBoxValueDataSource>
				<CheckBoxDisplayDataSource>
					<TextData>check this one
too</TextData>
				</CheckBoxDisplayDataSource>
			</CheckBox>
			<CheckBox>
				<CheckBoxValueDataSource>
					<TextData>4</TextData>
				</CheckBoxValueDataSource>
				<CheckBoxDisplayDataSource>
					<TextData>not me though
</TextData>
				</CheckBoxDisplayDataSource>
			</CheckBox>
		</CheckBoxGroup>
<!--END OF XML-->

XSL: (please note that this stuff is pretty screwed up right now.. a)
I'm using the shortcut LotusXSL java object tagging and b) the script is
pretty screwy, probably due to a concussion from my repeated
head-banging :-).  My efforts with the java code was to hide the <tr>
tags from the XSL so it wouldn't complain.  It works, but with the &lt;
problem described earlier.  The start() method simply spits out a <tr>.
The nextElement() method spits out a </tr><tr> IF the number of columns
specified in the CheckBoxGroup attribute has been reached.  The
remainder() method will spit out <td>&nbsp;</td> for each remainder
column.. ie if numberOfColumns = 2 and there are 7 checkboxes, then one
<td>&nbsp;</td> will be spit so that table integrity is kept.  The
with-param is used so that the ID of the checkbox assumes the ID of the
CheckBoxGroup so that all of the CheckBoxes in the group assume the same
HTML identity for CGI purposes.  A CheckBox can exist outside of a group
so if no param is passed in it will keep the original ID given it (I've
left out the ID stuff in the XML but trust me, it's there.

	<xsl:template match="CheckBoxGroup">
		<table> 
			<xsl:variable name="groupCols"
select="java:com.marketv.three60.server.xml.XslGroupColumn.new()"/>
			<xsl:variable name="numCols"
select="./@numberOfColumns/text()"/>
			<xsl:if test="java:setColSize($groupCols,
$numCols)" />
			<xsl:variable name="start"
select="java:start($groupCols)"/>
			<xsl:copy-of select="$start"/>
			<xsl:for-each select="CheckBox">
				<td>
					<xsl:apply-templates select=".">
						<xsl:with-param
name="ID" select="../../@id"/>
					</xsl:apply-templates>
				</td>
				<xsl:copy-of
select="java:nextElement($groupCols)"/>
			</xsl:for-each>
			<xsl:copy-of
select="java:remainder($groupCols)"/>
		</table>
	</xsl:template>
	<xsl:template match="CheckBox">
		<xsl:param name="ID" select="../@id"/>
		<xsl:choose>
			<xsl:when test="./@checked = 'true'">
				<input type="checkbox" checked=""
name="{$ID}" value="{./CheckBoxValueDataSource/TextData/text()}">
					<xsl:value-of
select="./CheckBoxDisplayDataSource/TextData/text()"/>
				</input>
			</xsl:when>
			<xsl:otherwise>
				<input type="checkbox" name="{$ID}"
value="{./CheckBoxValueDataSource/TextData/text()}">
					<xsl:value-of
select="./CheckBoxDisplayDataSource/TextData/text()"/>
				</input>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

Please feel free to rip this apart.. I'm prepared for an educational
session here so that I can be the best XSL author I can possibly be :-).
And thanks again for all of your help.

Dave

> -----Original Message-----
> From:	David Lamy 
> Sent:	Thursday, December 02, 1999 9:34 AM
> To:	'XSL-List@xxxxxxxxxxxxxxxx'
> Subject:	HTML characters being converted
> 
> Hello all--
> 
> I'm using my XSL stylesheet to create HTML.. one of the 
> "challenges" I've run into are situations where I need to 
> conditionally output only half of a tag group (i.e. <tr> but 
> not </tr>) in an XSL block.. if I only put in half of the 
> group, the stylesheet ceases to be well-formed, and I get 
> angry messages from both my XML writer and the XSL processor.
> 
> So, I thought I would perform the condition processing and 
> subsequent output in a Java class so that the XSL processor 
> would not complain about well-formedness.. good idea, and the 
> code runs, but in the resultant HTML, the "<" in the "<tr>" 
> tag mysteriously becomes a "&lt;"!  The ">" doesn't get 
> converted, however.  But, this is enough to screw up the 
> HTML, since the "&lt;tr>" tag is rendered in the browser 
> rather than being identified as an HTML tag.
> 
> Does anyone have any ideas on this problem(s)?  I'm open both 
> to solutions for the well-formedness issue as well as the 
> character conversion issue.
> 
> Details on the scenario follow:
> 
> The XML is generated by a screen designer that allows a user 
> to graphically define a screen.  One of the graphical 
> components is a CheckBox group.  An attribute of the 
> CheckBoxGroup is the number of columns in the group.  The 
> subelements are the checkboxes themselves.  I need to render 
> these checkboxes as a group according to the number of 
> columns.. so I'm creating an HTML table, with each <tr> being 
> composed of as many <td>s as the number of columns.. so you 
> see my need for conditional outputting of <tr> and </tr> 
> tags.. I'm keeping a counter of how many <td>s I've outputted 
> for a <tr> and conditionally I want to spit out a </tr> if 
> the counter has reached the number of columns value.
> 
> Thanks in advance for your help!! 
> 
> Dave Lamy
> MarketVision, Inc.
> dlamy@xxxxxxxxxxx
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread