[xsl] targeting the 'first' instance of the same element in variable structures

Subject: [xsl] targeting the 'first' instance of the same element in variable structures
From: "Jean-Paul Rehr rehrjb@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 2 Jul 2024 10:33:59 -0000
Dear XSL list,

I am trying to target a specific <head> which can appear nested within a
variable number of <div> and  possible <list> elements. In the three
examples below I have put in red the <head> element I want to target with
the same XSL template. In my way of thinking, it is always the first
appearance of <head> no matter how deep or shallow it may be nested. But I
am having trouble conceiving a path that can take into account the variable
depth. Any thoughts about how to target this?

Many thanks in advance for any assistance,
JPR

    <div>
        <div>
            <div>
                  <head>Title</head> <!-- nested in 3 divs -->
                  <p>some content</p>
             </div>
        </div>
        <div>
             <head>Title</head>
              <p>some content</p>
         </div>
    </div>

    <div>
           <div>
                  <head>Title</head> <!-- nested in 2 divs -->
                  <p>some content</p>
            </div>
            <div>
                  <head>Title</head>
                  <p>some content</p>
           </div>
   </div>

    <div>
        <div>
            <div>
                 <list>
                      <head>Title</head> <!-- nested in 3 divs and list -->
                      <item></item>
                      <item></item>
                 </list>
             </div>
             <div>
                 <head>Title</head>
                 <p>some content</p>
             </div>
        </div>
    </div>

I am trying to select the first <head>

Current Thread