[thelist] Generating html links with XSLT

Dave Merrill dmerrill at usa.net
Wed Dec 28 14:14:00 CST 2005


Hi Volkan, thanks for jumping in. I know about zvon; I'm using Cooktop for
some of my experiments, and it has link there in its Help menu.

I also understand your js-based ideas to avoid having to output @name inside
presetRecall's params, but I'd rather get this working if I can. It seems
cleaner to me, more like what I'd do in straight html or a server-side
language I know better than xslt. I'm also sure this kind of thing will come
up in other contexts, so I'd just like to understand how to do it.

In any case, not from anything I saw on zvon, I've started looking in this
direction:
-----------------------
<a href="#">
	<xsl:attribute name="onclick">
    		<xsl:value-of select="concat('presetRecall(', @name, ')')"/>
  	</xsl:attribute>
  	<xsl:text>Recall</xsl:text>
</a>
-----------------------

That's getting close; the result is:
-----------------------
<a href="#" onclick="presetRecall(foo)">Recall</a>
-----------------------

...where 'foo' (w/o the quotes) is the actual literal value of that node's
'name' attribute. Only thing missing is the quotes I need around the value,
which I still haven't seen a way to do.

I tried this for the select:
-----------------------
select="concat('presetRecall(&#39;', @name, '&#39;)')"
-----------------------
... but got:
ERROR: Description: Expected token ')' found 'STRING'.

I also tried using fn:codepoints-to-string(34), but 'fn' is an unrecognized
namespace, and the function can't be found without it. It looks like that's
not implemented yet in either Cooktop or the libraries underlying ColdFusion
(server-side language used for this).

Any ideas from here? (And thanks again...)

Dave Merrill


> >It seems that the XLT parser considers onclick to be an
> attribute of the <a>
> >element (it is), and isn't happy with un-escaped "<" chars in
> what it thinks
> >is literal attribute text.
>
> You're right.
>
> Here is a good place to start and advance:
>
> http://www.zvon.org/xxl/XSLTutorial/Output/index.html
>
> ...
>
> XSLT is an XML file and it has to conform XML snytax.
>
> in
>
> presetRecall('<xsl
>
> < indicates the start of a tag. However another tag has already started
> (<a href="#") before and it has not ended yet. Thus it is a snytax
> error as the parser indicates.
>
> For a quick and dirty solution you may use:
>
> <a href="#"
> onclick="presetRecall(this.childNodes[0].nodeValue)"><xsl:value-of
> select="@name"/></a>
>
> or
>
> <a href="#" onclick="presetRecall(this.innerHTML)"><xsl:value-of
> select="@name"/></a>
>
> or
>
> <a href="#"
> onclick="presetRecall(document.getElementById('label1').innerHTML)
> ">Recall:
> <label id="label1"><xsl:value-of
> select="@name"/></label></a>
>
> Both are quick suggestions and none of them is tested but
> I hope you got the point.
>
> I'm not sure but there may be more elegant ways of doing this. Buf if
> there is a way I'm pretty sure it would be listed in an example at
> zvon.org.
>
>
> HTH,
> --
> Volkan Ozcelik
> +>Yep! I'm blogging! : http://www.volkanozcelik.com/volkanozcelik/blog/
> +> My projects/studies/trials/errors : http://www.sarmal.com/
> --
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
>





More information about the thelist mailing list