xsl-list
[Top] [All Lists]

Re: [xsl] Bibliography author repetition handling

2017-10-09 16:21:54
Eliot,

Chuck may indeed want a function to normalize his associating value
(identifying the lead author), from which is-a-repetition logic is
derived. However, your suggestion takes us down a different pathway
altogether:

<xsl:function name="is-a-repetition" as="xs:boolean">
  <xsl:param name="who" as="element(bibl)"/>
  <xsl:sequence
   select="local:cited-author(.) =
preceding-sibling::bibl[1]/local:cited-author(.)"/>
</xsl:function>

Now we don't need the grouping any more at the XSLT level, we just
match it the way you have.

I dare say it may not be as efficient under the hood as the grouping
approach (Syd what do you think?) but over Dr Muller's runtime x data
set, that might not matter much.

Cheers, Wendell




On Mon, Oct 9, 2017 at 2:05 PM, Eliot Kimber ekimber(_at_)contrext(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Yes, in this case different modes might be overkill for just this one 
difference. It’s just that passing a parameter to do then do a choose inside 
a template just doesn’t feel right. There’s an argument to be made for 
consistency of approach—in my experience these things tend to not be just 
one, but the first of many to come…

If the check was one that could be easily put into a function, which this one 
does not seem to be, then I might use that function in the match expression 
rather than modes:

<xsl:template match=”bibl[local:is-a-repetition(.)]”>

Cheers,

Eliot
--
Eliot Kimber
http://contrext.com



On 10/9/17, 10:35 AM, "Wendell Piez wapiez(_at_)wendellpiez(_dot_)com" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

    Eliot didn't I say "you might prefer a mode"? :-)

    Just to remark I agree with your proposal to prefer modes over
    parameters for this kind of thing -- most of the time.

    This is a case where the only difference between the two pathways over
    bibl contents are identical except for a single element ... since
    bibl/* includes a lot, that means a fair amount of 'mode overhead' to
    handle the single difference.

    For that reason I might be willing to put up with an xsl:choose here,
    or functional equivalent ...

    <xsl:template match="bibl/author[1]">
      <xsl:param name=”repeat” tunnel=”yes” select=”false()”/>
      <xsl:apply-templates mode="repeating" select=".[$repeat]"/>
      <xsl:if test="not($repeat)">
         ...
      </xsl:if>
    </xsl:template>

    (Okay, I might leave a comment to help.)

    Cheers, Wendell

    On Mon, Oct 9, 2017 at 11:13 AM, Eliot Kimber 
ekimber(_at_)contrext(_dot_)com
    <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
    > No argument with Wendell’s general solution, just one small coding 
style twiddle:
    >
    > Instead of this:
    >
    >        <xsl:apply-templates select="current-group() except .">
    >           <xsl:with-param tunnel="yes" name="repeat" select="true()"/>
    >        </xsl:apply-templates>
    >
    > I would probably use a distinct mode for the repeated items:
    >
    >        <xsl:apply-templates select="current-group() except ." 
mode=”repeated-bib-items”/>
    >
    > I’ve come to accept that preferring templates and modes over passing 
state is the best XSLT style.
    >
    > All the items that have no difference in behavior in the two modes can 
simply match in both modes:
    >
    > <xsl:template match=”bibl” mode=”#default repeated-bib-items”>
    >   <xsl:apply-templates mode=”#current-mode”/>
    > </xsl:template>
    >
    > Otherwise there’s going to have to be a choose instruction to check the 
“repeat” parameter:
    >
    > <xsl:template …>
    >   <xsl:param name=”repeat” tunnel=”yes” select=”false()”/>
    >  <xsl:choose>
    >    <xsl:when test=”$repeat”>
    >      …
    >   </xsl:when>
    >   <xsl:otherwise>
    >     …
    >   </xsl:otherwise>
    > </choose>
    > </xsl:template>
    >
    > Better to put the choice in the mode and/or match expression.
    >
    > Cheers,
    >
    > E.
    > --
    > Eliot Kimber
    > http://contrext.com
    >
    >
    >
    > On 10/9/17, 9:58 AM, "Wendell Piez wapiez(_at_)wendellpiez(_dot_)com" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
    >
    >     Hi,
    >
    >     I think Chuck wants group-adjacent.
    >
    >     Chuck, what Martin is hinting is that rather than testing each bibl
    >     (each as you match it) to see whether it is a "repeat" or not, you
    >     first group all the bibls by their (analytic) author, then every
    >     member of the group after the first is a repeat.
    >
    >     (Define "repeat" as "bibl that should get '----' instead of a lead
    >     author's name by virtue of its having the same lead author as its
    >     immediate predecessor".)
    >
    >     This means that most of your groups will have only one member, but
    >     once in a while (when authors are repeated in runs) you will have a
    >     group of two or even more members, only the first of which is not a
    >     repeat.
    >
    >     Due to a design quirk in XSLT (semantics of "." inside groups), you
    >     can code this fairly elegantly:
    >
    >     <xsl:for-each-group select="bibl" group-adjacent="gimme-author()">
    >        <!-- apply templates to the first member -->
    >        <xsl:apply-templates select=".">
    >        <!-- apply templates to the rest w/ a param -->
    >        <xsl:apply-templates select="current-group() except .">
    >           <xsl:with-param tunnel="yes" name="repeat" select="true()"/>
    >        </xsl:apply-templates>
    >     </xsl:for-each-group>
    >
    >     Notes:
    >
    >     * No element is created for the group since the grouping is only to
    >     sort them into categories.
    >
    >     * gimme-author() will be whatever XPath (path or other expression)
    >     indicates the value to be grouped on (i.e. the leading author name
    >     however normalized).
    >
    >     * inside the group, "." refers only to the first member of the 
group,
    >     so "current-group() except ." returns all the others.
    >
    >     * Leaving it to you to figure out what to do at the receiving end 
with
    >     the Boolean parameter $repeat ... although I've indicated
    >     "tunnel='yes'" to leave another clue as to how it might be done. Or
    >     instead of a parameter you could also use a mode here to distinguish
    >     between handling the normal cases and the repeat cases. (Presumably
    >     they are the same except for how they treat that author.)
    >
    >     * group-by will have a similar effect to group-adjacent but only if
    >     the nodes are already in their final sorted order; if there is some
    >     anomaly in the listing, group-adjacent is more robust (and will
    >     reflect that anomaly not reorder around it).
    >
    >     It's been a few days, so you may already have tackled this. Still 
it's
    >     a fun little problem.
    >
    >     Cheers, Wendell
    >
    >
    >
    >     On Wed, Oct 4, 2017 at 4:18 AM, Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de
    >     <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
    >     > Am 04.10.2017 um 08:25 schrieb Charles Muller 
acmuller(_at_)l(_dot_)u-tokyo(_dot_)ac(_dot_)jp:
    >     >>
    >     >> In a TEI <biblStruct> bibliography that uses 
biblStruct/*/author/surname
    >     >> (etc), I have managed to write the code that checks if the 
author name in
    >     >> the prior <biblStruct> is the same, in which case the output is 
---. rather
    >     >> than the author's name. It works fine, but I'm running into a 
problem where
    >     >> there the first author name is the same as that of the prior 
<biblStruct>
    >     >> entry, but there are also multiple authors, in which case the 
full name
    >     >> should be printed out.
    >     >>
    >     >> I thought that one way I might resolve this is to test if the 
number of
    >     >> authors in the prior entry is the same as this one, but I can't 
get it to
    >     >> work. I also don't know if this is even the best way of handling 
this. The
    >     >> XML is like this:  (present output here:
    >     >> http://www.acmuller.net/articles-shisou.html)
    >     >
    >     >
    >     > To me this sounds like a grouping problem where you want to group 
your
    >     > biblStruct elements with a composite key mad up of 
analytic/author, I am not
    >     > sure whether you want group-adjacent or group-by.
    >     >
    >     >
    >
    >
    >
    >     --
    >     Wendell Piez | http://www.wendellpiez.com
    >     XML | XSLT | electronic publishing
    >     Eat Your Vegetables
    >     _____oo_________o_o___ooooo____ooooooo_^
    >
    >
    >
    >



    --
    Wendell Piez | http://www.wendellpiez.com
    XML | XSLT | electronic publishing
    Eat Your Vegetables
    _____oo_________o_o___ooooo____ooooooo_^







-- 
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>