Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2008, 12:26 PM
Registered User
 
Join Date: Feb 2008
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.
 
Old February 27th, 2008, 12:33 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old February 27th, 2008, 12:56 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old February 27th, 2008, 01:00 PM
Registered User
 
Join Date: Feb 2008
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






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.