RE: [xsl] Re; Grouping Titles under Correct Category

Subject: RE: [xsl] Re; Grouping Titles under Correct Category
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 13 May 2007 23:22:44 +0100
>'Disable-output-escaping' is used to mask specific HTML characters that
appear in the HTML output.  For
example '&amp;'  

Well, none of your titles contains any characters that need to be escaped,
so disabling escaping has no effect. If a title did contain a character that
needs to be escaped, then not escaping it would produce invalid output, and
I can't see why you want to produce invalid output.

> This code:
> 
> string-length(category) !=
> string-length(following::category)
> 
> is wildly out.

Sorry I wasn't more specific.

(1) Why are you comparing the length of the category rather than the
category itself? Is there some reason for believing that different
categories will always have different string-lengths?

(2) In XSLT 2.0, applying string-length to a value containing more than one
node is an error, and following::category will usually select more than one
node. In 1.0, it's taken to mean following::category[1]. If you mean
following::category[1] then it's best to write it that way for clarity and
forwards compatibility.

(3) In your example the category elements are all siblings, so it would be
much more efficient to write following-sibling::category[1] rather than
following::category[1].

(4) Your expression will be true for the last item of a consecutive sequence
of items with the same category [length]. But you want to output the
category name before the items in that category, so you surely want an
expression that is true for the first category in a consecutive sequence.
You're compensating for this with the logic:

    <xsl:variable name="tracker"
select="position()-1"/>
      <xsl:if test="category != ''">
        <xsl:if test="string-length(category) !=
string-length(following::category)">
           <b><xsl:value-of
select="category"/></b><br/>         
         </xsl:if>
      <xsl:value-of select="//item[$tracker]/title"
disable-output-escaping="yes"/><br/> 

which seems to ensure that when processing an item, you output the title of
the previous item. But this doesn't move the category name to the front of
the group, it moves it to just before the last title in the group. It also
means that the last item in the list isn't output at all.

So I'd suggest you go back to Jeni's pages and follow her examples more
closely.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Brent Solly [mailto:free12spir@xxxxxxxxx] 
> Sent: 13 May 2007 22:56
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Re; Grouping Titles under Correct Category 
> 
> I guess what you mean by 'wildly out' is the line of code is 
> obsolete.  Okaay.  
> 
> 'Disable-output-escaping' is used to mask specific HTML 
> characters that appear in the HTML output.  For
> example '&amp;'   
> 
> I went to Jen's page previously before coming to this forum. 
> 
> Thanks for your help.
> -----------------------------------
> Date: Fri, 11 May 2007 21:09:38 +0100
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> From: "Michael Kay" <mike@xxxxxxxxxxxx>
> Subject: RE: [xsl] Grouping Titles under Correct Category
> Message-ID: <017501c79408$4e3da320$6401a8c0@turtle>
> 
> This is a completely standard grouping problem.
> Grouping is much easier
> in
> XSLT 2.0 using xsl:for-each-group, but if you really need to 
> stick with 1.0, go to 
> http://www.jenitennison.com/xslt/grouping to learn how to do it.
> 
> This code:
> 
> string-length(category) !=
> string-length(following::category)
> 
> is wildly out.
> 
> And why do you want to disable-output-escaping?
> 
> Michael Kay
> http://www.saxonica.com/
> 
> Any state, any entity, any ideology that fails to recognize 
> the worth, the dignity, the rights of man - That state is obsolete.
> -spooky man from Twilight Zone (1961)
> 
> http://s8.invisionfree.com/Solo_Tee_and_Company/index.php?act=idx

Current Thread