Re: [xsl] max string-length for context grandchildren

Subject: Re: [xsl] max string-length for context grandchildren
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Wed, 5 Oct 2011 09:50:08 +0100
>    <list type="deflist">
>        <head>This is a test list</head>
>        <defitem>
>            <label>Processed by</label>
>            <item>Lynette Stoudt</item></defitem>
>        <defitem>
>            <label>Date Completed</label>
>            <item>February 1999</item></defitem>
> I'm trying to determine which of the three <label> elements is the longest,
so my desired output is: 14, which is the string length of
list/defitem/label[2].  The calculation needs to be made while <list> is the
context node.  I've tried two different approaches:

<xsl:template match="list">
  <xsl:variable name="max-lable-length"
select="max(defitem/label/string-length(.))" as="xs:integer"/>
  <xsl:variable name="longest-label"
select="defitem/label[string-length(.) = $max-label-length]"

That's assuming there is always guaranteed to be a defitem/label, if
not then you would need to adjust the cardinalities to cope with not
finding anything.

Andrew Welch

Current Thread