[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

conditionals & attributes

Subject: conditionals & attributes
From: "Lawton, Scott" <slawton@xxxxxxxxxxxx>
Date: Fri, 6 Nov 1998 11:56:48 -0500
conditionals
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)}">
else:
	<LABEL>

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

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

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

	</LABEL>

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)}"
three="{attribute(bar)}">
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)">
			for="{attribute(target)}"
			</xsl:when>
		<xsl:when test="attribute(foo)">
			two="{attribute(foo)}"
			</xsl:when>
		<xsl:when test="attribute(bar)">
			three="{attribute(bar)}"
			</xsl:when>
		</xsl:insertTag>

thoughts?

Scott

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:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.