conditionals & attributes

Subject: conditionals & attributes
From: "Lawton, Scott" <slawton@xxxxxxxxxxxx>
Date: Fri, 6 Nov 1998 11:56:48 -0500
Many attributes in an arbitrary XML file are optional.  If present, I'd like
my XSL to do something with them.  If absent, leave them out (or perhaps add
some default value).

For example, if there's a "target" attribute, I want to output:
	<LABEL for="{attribute(target)}">

Naturally the following gives an error since it's not well-formed:

		<xsl:when test="attribute(target)">
			<LABEL for="{attribute(target)}">

	<!-- lots of stuff here that is common to both cases -->


I suppose the answer in this case is to put the common stuff in a macro --
assuming that macro invocation can be nested.  (The above snippet is from a
macro already.)

But maybe there's a more elegant solution, especially for multiple
attributes?  How about an option to exclude the attribute if the value is
empty?  Then I could just do:
	<LABEL for="{attribute(target)}" two="{attribute(foo)}"
and would get a different result depending on which attributes had values.

Or maybe there's a way to build an output tag piecemeal, e.g.
	<xsl:insertTag name="LABEL">
		<xsl:when test="attribute(target)">
		<xsl:when test="attribute(foo)">
		<xsl:when test="attribute(bar)">



P.S. I realize the indendation is somewhat non-traditional, but it makes
sense if you use an outliner for editing....

 XSL-List info and archive:

Current Thread