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 October 4th, 2006, 02:50 PM
Registered User
 
Join Date: Oct 2006
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


 
Old October 4th, 2006, 03:15 PM
Authorized User
 
Join Date: May 2006
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>
 
Old October 4th, 2006, 03:39 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old October 4th, 2006, 03:44 PM
Registered User
 
Join Date: Oct 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Bill







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





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