Conditional actions in XSL?

Peter Murray-Rust peter at
Wed Jan 28 12:26:46 GMT 1998

[Forwarded to the list from Dr. Zheng Min]

>>>I played with XSL and MSXSL in the last few days. One thing I'm trying to
>>>is to drop all the elements with date attribute < a specified date.
>>>with my understanding of XSL, I couldn't figure out a good way to do this.
>>>The normal ways, I can think of, to do this are either:
>>>1.     XSL supports conditional actions, such as:
>>>        <target-element ...>
>>>        if condition
>>>            <children/>
>>>        else
>>>            do nothing
>>>        end
>>>(I don't believe XSL has such a feature, unless I overlooked something.
>>>only thing I see similar is the attribute rules but it can only be
>>>'=Value'), or
>>>2.    in the scripts, one can write:
>>>        function filter (e) {
>>>            if calc(attribute) then
>>>                do something
>>>                <children/>
>>>            else
>>>                do something else
>>>            end
>>>    and in XSL body, one can use the following rules to filter output
>>>without skipping (or including all) its descendants:
>>>            <target-element/>
>>>            <eval>filter(this)</eval>
>>>There is a "hacking" way I can think of, but unfortunately, I can't test
>>>because MSXSL doesn't seem to support 'mode' yet. Anyways, the 'hacking'
>>>trying to do it to use something like:
>>>            function check(e) {
>>>                ......
>>>            }            /* return true or false */
>>>            .......
>>>            <rule>
>>>                <target-element/>
>>>                 <children mode="=check(this)"/>
>>>            </rule>
>>>            <rule mode="true">
>>>                .........
>>>            </rule>
>>>            <rule mode="false">
>>>                ......
>>>            </rule>
>>>I'm not sure if this works or not (it doesn't work with current MSXSL, at
>>>Can any knowledgeable people help me clarify the followings:
>>>1. Does XSL supports either the above 2 scenarios (i.e. condition in
>>>rules or processing descendants in scripts). I may overlook something.
>>>2. If neither of above is available in XSL, what are the good work around?
>>>Will my 'hacking' work?
>>>Conditional action is a common feature. Very often an SGML/XML application
>>>needs to filter certain elements based on calculation (of attribute
>>>IF XSL can't support this, I would say something essential is missing from
>>>Any comments?
Peter Murray-Rust, Director Virtual School of Molecular Sciences, domestic
net connection
VSMS, Virtual Hyperglossary

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at
Archived as:
To (un)subscribe, mailto:majordomo at the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at

More information about the Xml-dev mailing list