xsl-list
[Top] [All Lists]

Re: XSLT Grouping/Filtering issue with preceding/following axes

2005-08-05 14:03:47
Hi Joris,

Thanks for pointing that out.  However, after fixing typo for some
reason the stylesheet is still not filtering/grouping correctly per
the following (especially the last <CodeId/> in the input xml file).:

Any idea as to what is going on here?  Thanks!
--

XSL:

        <xsl:template match="/">
        
                <xsl:element name="Root"> 
                
<!-- Ok, this works for FRED as the group is filtered with no duplicates -->
  <xsl:variable name="uh" select="//Record[CodeId='FRED']"/>
  <xsl:element name="Copy">
      <xsl:copy-of select="$uh"/>
   </xsl:element>
   <xsl:element name="Filter">
      <xsl:copy-of
select="$uh[not(AttributeName=preceding::*/AttributeName)]"/>
   </xsl:element> 

         <!-- However, this does not work for the 30DAYPM as it is missing
the LT CodeId group -->
  <xsl:variable name="uh2" select="//Record[CodeId='30DAYPM']"/>
  <xsl:element name="Copy">
      <xsl:copy-of select="$uh2"/>
   </xsl:element>
   <xsl:element name="Filter">
      <xsl:copy-of
select="$uh2[not(AttributeName=preceding::*/AttributeName)]"/>
   </xsl:element> 
         
   <!-- This works but I'm sure is not the best way to do this... -->
  <xsl:variable name="uh" select="//Record[CodeId='30DAYPM']"/>
  <xsl:element name="Copy">
      <xsl:copy-of select="$uh"/>
   </xsl:element>
   <xsl:element name="Filter">
      <xsl:copy-of
select="$uh[(not(AttributeName=preceding::*/AttributeName) and
          position()=1) or (not(AttributeName=following::*/AttributeName))]"/>
   </xsl:element>               
         
</xsl:element>
        </xsl:template>

XML:


<Results>
        <Record>
                <CodeId>FRED</CodeId>
                <AttributeName>LT</AttributeName>
                <OID>647f802e5f8675a6</OID>
                <Id>AU  100-1</Id>
                <AttributeValue>YES</AttributeValue>
        </Record>
        <Record>
                <CodeId>FRED</CodeId>
                <AttributeName>CPQ</AttributeName>
                <OID>647f802e5f8675a6</OID>
                <Id>AU  100-2</Id>
                <AttributeValue>YES</AttributeValue>
        </Record>
        <Record>
                <CodeId>30DAYPM</CodeId>
                <AttributeName>LT</AttributeName>
                <OID>daa575325f8675a6</OID>
                <Id>AU  100-3</Id>
                <AttributeValue>YES</AttributeValue>
        </Record>
        <Record>
                <CodeId>30DAYPM</CodeId>
                <AttributeName>CSW</AttributeName>
                <OID>daa575325f8675a6</OID>
                <Id>AU  100-4</Id>
                <AttributeValue>YES</AttributeValue>
        </Record>
        <Record>
                <CodeId>FRED</CodeId>
                <AttributeName>LT</AttributeName>
                <OID>647f802e5f8675a6</OID>
                <Id>AU  100-5</Id>
                <AttributeValue>YES</AttributeValue>
        </Record>
        <Record>
                <CodeId>FRED</CodeId>
                <AttributeName>CPQ</AttributeName>
                <OID>647f802e5f8675a6</OID>
                <Id>AU  100-6</Id>
                <AttributeValue>YES</AttributeValue>
        </Record>
        <Record>
                <CodeId>30DAYPM</CodeId>
                <AttributeName>LT</AttributeName>
                <OID>daa575325f8675a6</OID>
                <Id>AU  100-7</Id>
                <AttributeValue>YES</AttributeValue>
        </Record>
        <Record>
                <CodeId>30DAYPM</CodeId>
                <AttributeName>CSW</AttributeName>
                <OID>daa575325f8675a6</OID>
                <Id>AU  100-8</Id>
                <AttributeValue>YES</AttributeValue>
        </Record>
</Results>

On 8/5/05, Joris Gillis <roac(_at_)pandora(_dot_)be> wrote:
Tempore 16:51:16, die 08/05/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Jacquo Johnson 
<genxgeek(_at_)gmail(_dot_)com>:

   <!-- This doesn't work...group is not filtered correctly -->
   <xsl:variable name="uh" select="//Record[CodeId='FRED']"/>
   <xsl:element name="Copy">
       <xsl:copy-of select="$uh"/>
    </xsl:element>
    <xsl:element name="Filter">
       <xsl:copy-of 
select="$uh[(not(AttributeName=preceding::*/AttributeName)]"/>
    </xsl:element>

There's a typo in the Xpath. It should be
$uh[not(AttributeName=preceding::*/AttributeName)]

It more common to use the Muenchian grouping technique for solving problems 
like this.

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«Φιλήκοον ειναι μαλλον η φιλόλαλον»  - Κλεόβουλος

--~------------------------------------------------------------------
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>
--~--