[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] conditionals & attributes
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|