[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: How to do an 'existence' test in XSL?
Hi George,
At 03:20 PM 12/22/2004, you wrote: In this case the OP was grasping for a solution to a *simple* requirement, in his words. It's poor form if XSL can only offer a complex solution when there is a simple need. Well sure: agreed on all points. But don't leave long-term maintainability and usability out of the picture. Maybe I wasn't paying attention (if so I apologize): but I didn't take it as given that the values were known ahead of time, or always would be. Perhaps hashing this out with the OP would have been a good idea (but then we couldn't have this meta-conversation). Often, in fact (and I say this not for your benefit, as you appear to have thought this through, but for others following along), it can be a tricky judgement call whether to implement the more general solution, which is a bit harder, or just hard-code the particular solution you know will work in this particular instance. Sometimes it's not clear when a stylesheet is a one-off that will never be used again over another data set -- or what constraints over the input data can be assumed if it is not. In such cases, I'll usually prefer to err on the side of generality. FWIW, there are also intermediate solutions. For example, your stylesheet could contain a lookup table of expected values, and your template can simply iterate over this list and write out the node when a member of the set represented by the current list item can be identified. This is hard-coded, like the solution you offered, but slightly easier to maintain and extend for new values. input: <gui type="alertBox">...</gui> <gui type="tooltip">...</gui> <gui type="help">...</gui> <gui type="tooltip">...</gui> <gui type="alertBox">...</gui> <gui type="tooltip">...</gui> <gui type="help">...</gui> stylesheet <xsl:variable name="gui-type-list"> <gui type="alertBox"/> <gui type="tooltip"/> <gui type="alertbox"/> </xsl:variable> <xsl:variable name="gui-types" select="document('')/*/xsl:variable[@name='gui-type-list']/gui"/> <xsl:variable name="all-guis" select="//gui"/> and then, in a template, <xsl:for-each select="$gui-types"> <xsl:if test="@type = $all-guis/@type"> <gui type="{@type}"/> </xsl:if> </xsl:for-each> This would run pretty fast. (You be the judge of how simple it is.) In any case, thanks for the reminder that generality is not always the most important virtue in a stylesheet. I think the OP is getting his money's worth this time. :-> Cheers, Wendell
|
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
|