[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Selecting only the first node that matches.


Subject: [xsl] Selecting only the first node that matches.
From: "Shawn O. McKenzie" <smckenzie@xxxxxxxxxxx>
Date: Mon, 04 Nov 2002 17:50:59 -0800

If possible, I need to be able to select only the first instance of a match. Consider the following:

<ancestor name="1">
   <propertyref name="foo"/>
   <ancestor name="2">
       <propertyref name="bar"/>
       <ancestor name="3">
           <propertyref name="foo"/>
           <ancestor name="4">
                <propertyref name="fnord"/>
             </ancestor>
        </ancestor>
   </ancestor>
</ancestor>

I would like to be able to match on the first ancestor element that has a propertyref/@name of foo, but not the second one. These nested "ancestor" elements vary in depth and can have any number of propertyref attributes.

Not sure if this will help, but here is some pseudocode for the big picture of what I am trying to do. We are getting structured xml out of our compiler and attempting to automate some of our api documentation. For properties that are documented in a specific class, we pull in an author created xml file. For inherited properties I need to include information about what unit/class the property was documented in so that I can build an html link. Each class in the compiler output includes an ancestor list (similar to my example above). However, there is not enough to know which ancestor is where the property was actually documented. I plan to solve this with recursion, but am having trouble with only matching on the "closest ancestor" in the pseudocode below.

template propertylinks2
find properties in the closest ancestor that are not in the members list of the class we are processing.
call template recursion with parameters for the file to open



Template recursion, with parameter(s)for file to open
case1
when property was not documented in this class, call template recursion with parameters of immediate ancestor
case2.
when file does match, include unit/class info for building a link when transforming to html.







XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




Current Thread
Keywords
xml