[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Variable in XPath
Hi Garvin,
see my comments. Garvin Riensche wrote:
though this will work for the quick and dirty solution, you may want to use a more flexible solution if you have many attributes to match. I.e., provide an XML file with the settings that you search for, or make the attribute names variables as well. Note (see all the earlier responses) that you should not use an xsl:variable, but an xsl:param instead. When writing the stylesheet I dont't know which classes are goint to be selected. This could be all classes, classes selected by id, classes selected by id and name, ect. So there are lots of possibilities - and even more if there are more attributes. The stylesheet would be very large if I would use a <xsl:when> for every possible combination. that would never be a good idea of course ;) So my idea was to use a default value for each variable, so that all (class) nodes are selected if the variable is not set. which is neither a good idea. ;)
well, apart from my previous post, which will still work well with your requirements (but you must adjust the predicates), consider this predicate or test: class[@id = $id or empty($id)][@owner = $owner or empty($owner)] or consider this (where the default is the current attribute): class[($id, @id)[1] = @id][($owner, @owner)[1] = @owner] Note however the subtle differences between the two: the first will be true if there is no @id on class element, if there is no $id on the commandline. The second will be true if there is no $id on the commandline, but will be false if there is no @id at all on the current class element. Same holds for $owner etc.
Not really. You cannot easily set a value that always evaluates to true in an equality expression. And why would you want that? My second solution above uses the current attribute as a default value. It would be great if that would work somehow because with lots of <xsl:when>s I think it would be much more complicated (considering more attributes). if you have lots of xsl:whens, there's something wrong ('wrong' is in the eye of the beholder of course) in your design of your stylesheet. Perhaps you do not want xsl:when at all, perhaps you want to use apply-templates, because, if you have more than one match, you select all of them within the apply-templates call. Hth, Cheers, -- Abel Braaksma
|
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
|