Subject: xsl select statement
Posted By: pat123 Post Date: 4/19/2006 6:43:59 AM
Hi,

I am using this select statement to return unique clients from my xml file and put them into a drop down list.
//portfolio/campaign[@client_name][not(@client_name=preceding-sibling::campaign/@client_name)]

This line works perfect, but I also need another select statement to return unique creative types from my xml file.
Tried this:
//portfolio/campaign/creative[@client_type][not(@client_type=preceding-sibling::creative/@client_type)]

This is the struture of my xml

<portfolio>
    <campaign client_name="client1">
        <creative creative_type = "banner"></creative>
        <creative creative_type = "island"></creative>
        <creative creative_type = "banner"></creative>
    </campaign>
    <campaign client_name="client2">
        <creative creative_type = "banner"></creative>
        <creative creative_type = "island"></creative>
        <creative creative_type = "banner"></creative>
    </campaign>
    <campaign client_name="client3">
        <creative creative_type = "banner"></creative>
        <creative creative_type = "island"></creative>
        <creative creative_type = "banner"></creative>
    </campaign>
</portfolio>

The select statement for creative types should return only two results:
banner
island

But mine returns:
banner
island
banner
island
banner
island

It returns unique types for creatives with the same parent but ignores other campaigns.

I hope this is clear. I need a select statement that will return the proper result as shown above. Can anyone help?


Reply By: mhkay Reply Date: 4/19/2006 7:15:24 AM
In 2.0 of course you can simply use the distinct-values() function.

In 1.0, try

portfolio/campaign/creative/@creative_type[not(. = ../preceding::creative/@creative-type)]

or for better performance, use Muenchian grouping.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: pat123 Reply Date: 4/19/2006 8:17:36 AM
Thanks, that worked perfect.

portfolio/campaign/creative/@creative_type[not(. = ../preceding::creative/@creative_type)]


Go to topic 43123

Return to index page 310
Return to index page 309
Return to index page 308
Return to index page 307
Return to index page 306
Return to index page 305
Return to index page 304
Return to index page 303
Return to index page 302
Return to index page 301