[xsl] Re: xsl-list Digest 14 May 2007 05:10:00 -0000 Issue 1136

Subject: [xsl] Re: xsl-list Digest 14 May 2007 05:10:00 -0000 Issue 1136
From: Brent Solly <free12spir@xxxxxxxxx>
Date: Mon, 14 May 2007 03:26:05 -0700 (PDT)
Yes, if you look below, the xml file I am currently
working with does have different category names, and
the names can repeat as well.  

I understand the problem with the
'disable-out-escaping', in this particular example
there is no need for it because those targeted
characters don't exist.  

Yes, I'm going back to Jeni's page to review her
methods.  

Thanks for taking the time to respond. 

> Input XML
> ----------
> <?xml version="1.0" encoding="UTF-8"?>
> <rss>
> <channel>   
>       <item>
>          <title>Ogre Battle is sold out</title>
>          <description> There is a high demand for
this rare 
> game.</description>
>          <category>SNES</category>       
>       </item>
>       <item>
>          <title>Final Fantasy 3 Breaks FF2
Record</title>
>          <description>It was thought impossible to
outdo FF2 
> gameplay.</description>
>          <category>SNES</category>  
>       </item>
>       <item>
>          <title>SNES is the Ultimate System</title>
>          <description>This new system has
revolutionized 
> controller design.</description>
>          <category>SNES</category>   
>       </item>
>       <item>
>          <title>Sonic The Hedgehog an instant
success</title>
>          <description>A new Mario is been
born.</description>
>          <category>SEGA Genesis</category>
>       </item>
>       <item>
>          <title>Joe Montanna Talking Football is
amazing</title>
>          <description>Listen play by play in this
new form of 
> football game.</description>
>          <category>SEGA Genesis</category>
>       </item>
>  </channel>
> </rss>


Date: Sun, 13 May 2007 23:22:44 +0100
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Subject: RE: [xsl] Re; Grouping Titles under Correct 
Category 
Message-ID: <022d01c795ad$3a6532e0$6401a8c0@turtle>

>'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.



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