Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 27th, 2008, 12:26 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excluding Elements based on a Predicate Condition

Hello,
I have an issue with transforming an xml, the goal is to exclude <Source> element if the value of the attribute @guid has 'badguid', the element <client> and its attribute @guid are optional, meaning it may not be there all the time, here is my example:

XML:
----

<?xml version="1.0" encoding="utf-8"?>
<Feed>
    <Source>
        <BlackListedFor />
        <Link href="link1" />
    </Source>
    <Source>
        <BlackListedFor>
            <client guid="badguid" />
        </BlackListedFor>
        <Link href="link2" />
    </Source>
    <Source>
        <BlackListedFor />
        <Link href="link3" />
    </Source>
</Feed>

, and here is the XSLT
--------------------------

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/Feed">
        <xsl:copy>
            <xsl:apply-templates select="Source[BlackListedFor/client[@guid!='badguid']]"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>


I'm not able to cover all cases, what should I use here? conditional processing? a special predicate??

thanks.
Reply With Quote
  #2 (permalink)  
Old February 27th, 2008, 12:33 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Try using the not() function instead of != operator:

<xsl:apply-templates select="Source[BlackListedFor/client[not(@guid='badguid')]]"/>

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old February 27th, 2008, 12:56 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

Try replacing

select="Source[BlackListedFor/client[@guid!='badguid']]"

by

select="Source[not(BlackListedFor/client/@guid='badguid')]"

It's the difference between something that has an attribute A that is not equal to B, and something that does not have an attribute A that is equal to B.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old February 27th, 2008, 01:00 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks mhkay and samjudson !! mhkay solution worked :), and your comment does make sence now.

-Tamer

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
QUERY EXECUTION based on IF condition drani C# 0 November 9th, 2007 04:14 PM
Pls help - Sorting based on condition kalwinhobbess Crystal Reports 0 September 10th, 2007 10:47 AM
Count nodes based of if condition suri_1811 XSLT 1 December 7th, 2006 08:00 PM
Question about counting records based on condition TheBlueSky Crystal Reports 1 May 31st, 2006 03:35 AM
popup based on condition msrnivas General .NET 0 July 11th, 2005 05:52 PM



All times are GMT -4. The time now is 11:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.