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 | 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 October 4th, 2006, 02:50 PM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default selecting nodes that lack certain attributes

Hi All,

I have a need to select all nodes that are missing children that meet a certain criteria. I think it's best illustrated with an example:

<Root>
  <SomeTag Ordinal="1">
    <TagDetail N="Owner" V="Bob"/>
    <TagDetail N="Category" V="Good Stuff"/>
    <TagDetail N="Category" V="Foo"/>
  </SomeTag>
  <SomeTag Ordinal="2">
    <TagDetail N="Owner" V="Jerry"/>
  </SomeTag>
  <SomeTag Ordinal="3">
    <TagDetail N="Owner" V="Allison"/>
    <TagDetail N="ExpireDate" V="13 Aug 2007"/>
    <TagDetail N="Category" V="Foo"/>
  </SomeTag>
</Root>

I'd like to select all SomeTag elements that do not have a TagDetail child element with a N="Category" attribute. So in this case, the nodeset returned would be only the second SomeTag element, since it's the only one that doesn't have a TagDetail with a Category.

I thought it'd be possible with something like:

select="SomeTag/TagDetail[not(@N='Category')]"

but that doesn't work. Any help would be greatly appreciated!

Thanks
Bill


Reply With Quote
  #2 (permalink)  
Old October 4th, 2006, 03:15 PM
Authorized User
 
Join Date: May 2006
Location: Plovdiv, , Bulgaria.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to boen_robot
Default

Scince you want the SomeTag element, you should limit your selection up to it. Maybe something like:
Code:
SomeTag[not(TagDetail[@N='Category'])]
------
<xsl:for-each select="problem"><xsl:value-of select="solution"></xsl:for-each>
Reply With Quote
  #3 (permalink)  
Old October 4th, 2006, 03:39 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'd like to select all SomeTag elements that do not have a TagDetail child element with a N="Category" attribute

SomeTag[not(TagDetail/@N='Category')]

when you think about it your idea of

SomeTag/TagDetail[not(@N='Category')]

clearly can't work because it selects TagDetail elements and you're looking for cases where there isn't a TagDetail element to select.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old October 4th, 2006, 03:44 PM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That worked! Thanks a lot, much appreciated ...

Bill


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
Xpath - Selecting attributes bonekrusher XSLT 3 October 1st, 2008 12:27 PM
Selecting nodes of various namespace spencer.clark XSLT 8 August 5th, 2005 07:53 AM
XML DOM :modifying the existing nodes attributes i sharmasourabh54 XML 1 February 14th, 2005 05:04 AM
XPath - Selecting nodes based on attribute values billy_bob_the_3rd XML 4 December 1st, 2004 06:12 PM
Need to copy all nodes, attributes, and namespaces juaniux XSLT 4 October 22nd, 2004 04:39 PM



All times are GMT -4. The time now is 02:46 PM.


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