xsl-list
[Top] [All Lists]

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

2011-10-05 03:50:18
   <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]"
as="element(label)+"/>

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
http://andrewjwelch.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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