You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by August Gresens <au...@blackhammer.com> on 2000/05/15 18:27:29 UTC

writing html tags from Java extension

I want to write an extension that automates the creation of <option> 
tags for our stlyesheets. We have instances (a date drop down box for 
example) were we have to write out dozens of these tags, and the xsl 
method of doing this is really too verbose (see below under code).

Currently I'm trying to do this by creating an extension function in 
Java that generates a bunch of these tags as needed and returns a 
string. As in:

	public static String getOption()
	{
		String out = new String("<option>")
		return out;
	{

Ends up printing something like this to the html:

"&lt;option&gt;


I also tried this:

	public static String getOption()
	{
		String out = new String("<![CDATA[<option>]]>")
		return out;
	{

Which appeared as this in the browser:

&lt![CDATA[<option>]]&gt;

Is there any way to get around this problem returning strings, or 
must I do something more fancy, like create an extension element that 
will return a NodeList to the xslt, and then operate on the new nodes?

Or - perhaps -- I can call a template within xslt from Java, passing 
it the parameters on the fly?

thanks,

a


--> code to write an option tag --->


Here's the template to write an option tag using

<xsl:template name="option_tag">
         <xsl:param name="value">no_value</xsl:param>
         <xsl:param name="cur_val">no_curvalue</xsl:param>
         <xsl:param name="text">no_text_defined</xsl:param>

         <xsl:element name="option">
                 <xsl:attribute name="value"><xsl:value-of 
select="$value"/></xsl
:attribute>
                 <xsl:if test="$value = $cur_val">
                         <xsl:attribute name="selected">true</xsl:attribute>
                 </xsl:if>
                 <xsl:value-of select="$text"/>
         </xsl:element>
</xsl:template>


To write each option tag, however, the following must appear. 31 of 
these listed down the page cannot be the only way to do this!

<xsl:variable name="currentValue" 
select="account/trip[$trip]/contact/location"/>

<xsl:call-template name="option_tag">
<xsl:with-param name="value">Home</xsl:with-param> 
<xsl:with-param name="cur_val"><xsl:apply-templates 
select="$currentValue"/></xsl:with-param>
<xsl:with-param name="text">Home</xsl:with-param>
</xsl:call-template>
-- 
/////////////////////////
August Gresens
Black Hammer Productions
august@blackhammer.com
212 625-8980 ext 21
/////////////////////////