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

Subject: Re: [xsl] targeting the 'first' instance of the same element in variable structures
From: "David Birnbaum djbpitt@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 2 Jul 2024 11:24:15 -0000
Ah! I was reading carelessly. Itbs a pattern, rather than an
expression, so it matches independently on each div that has descendant
heads. You should be able to fine-tune it by adding a predicate, but
perhaps therebs a more elegant pattern that Ibm overlooking, and that
someone else will suggest. 

  On Jul 2, 2024, at 7:18b/AM, David Carlisle d.p.carlisle@xxxxxxxxx
  <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

  o;?

  On Tue, 2 Jul 2024 at 12:14, Jean-Paul Rehr rehrjb@xxxxxxxxx <xsl-list-service@lists.
  mulberrytech.com> wrote:

    >How about <xsl:template match="(div/descendant::head)[1]"> ?
    same result as Martin's solution, alas.

  Note you asked originally for an xpath not an xslt pattern (which is
  why I suggested select="(.//head)[1] ")the patterns shown will match
  the first head in _any_ div  but it seems you want the first head in
  the documents use / not div
  as the root of the pattern

    On Tue, Jul 2, 2024 at 1:08b/PM David Birnbaum djbpitt@xxxxxxxxx
    <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

      How about <xsl:template match="(div/descendant::head)[1]"> ?

        On Jul 2, 2024, at 7:04b/AM, Jean-Paul Rehr
        rehrjb@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
        wrote:

        o;?At first Martin's solution  <xsl:template
        match="(div//head)[1]"> looked like it would work. But
        then I started to test the various documents I have to
        work with, in particular at the most problematic. Below
        is an actual fragment, but I've put it in this Fiddle. As
        we can see it matched two items...it should only match
        the first. In bold below are what the template matched,
        in red bold what should be exclusively matched. 
        <div xml:id="michael-meld-dist-div-5Ehm2la0">
        <div xml:id="michael-meld-dist-div-1k784804"
        type="fulltext">
        <div xml:id="michael-meld-dist-div-23IEC0ec"
        type="prologus">
        <head>PREFATIO<note type="source">Indicem analyticum, qui
        ex vetusta exemplari Ms. in ceteris editionibus hoc loco
        legitur, ad   calcem  voluminis tomi rejecimus.</note>
        </head>
        <p xml:id="michael-meld-dist-p-k78i0214">Quisquis ad
        divine pagine lectionem erudiendus accedit, in principio
        considerare debet, que sit illius  Scripture materia,
        circa quam versatur ejus tractatus. Est autem illius
         principalis materia, opus restaurationis.</p>
        <div xml:id="michael-meld-dist-div-02847i24"
        sameAs="michaelis_0001" type="distinctio">
         <head>Opus conditionis et restaurationis</head>
         <p xml:id="michael-meld-dist-p-0M0t4368">Sunt enim duo
        opera : opus conditionis, et opus restaurationis. Opus
        conditionis est, quo factum   est ut essent, que non
        erant; opus restaurationis est, per quod meliorata sunt,
        que
         perierant. Opere conditionis factus est mundus cum suis
        elementis; opere restaurationis, Verbi incarnatio cum
        suis sacramentis. </p>
        </div>
        <div xml:id="michael-meld-dist-div-qA5X66Ks"
        sameAs="michaelis_0002" type="distinctio">
         <head>Sacre Scripture prestantia</head>
         <p xml:id="michael-meld-dist-p-E1v5wA1j">Ex quo
        manifestum est, quod Scriptura cunctis aliis precellit,
        tum materie dignitate, tum   profunditate, et
        subtilitate. Et si quis diligenter attendit, potest
        percipere quod omnes
         artes, tam liberales, quam naturales, ei tanquam domine
        famulantur. </p>
        </div>
         </div>
        </div>
         </div>

        On Tue, Jul 2, 2024 at 12:41b/PM Martin Honnen
        martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
        wrote:

          On 02/07/2024 12:34, Jean-Paul Rehr rehrjb@xxxxxxxxx
          wrote:

            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?

          You can do

          <xsl:template match="(div//head)[1]">

          in XSLT 3 (if the processor is up to it, I think
          early Saxon releases like 9.8 or 9.9 that are no
          longer supported, didn't support it, but current
          releases (11 and 12) certainly do.

          fiddle link

          XSL-List info and archiveEasyUnsubscribe (by email)

        XSL-List info and archiveEasyUnsubscribe (by email)

      XSL-List info and archiveEasyUnsubscribe (by email)

    XSL-List info and archiveEasyUnsubscribe (by email)

  XSL-List info and archiveEasyUnsubscribe (by email)

XSL-List info and archiveEasyUnsubscribe (by email)

Current Thread