Reputation: 58422
I am needing a little help with filtering my xml based on a property
I have the XML in the following format:
<?xml version="1.0" encoding="utf-8" ?>
<root id="-1">
<LandingPage id="1067" parentID="1050" level="2"
writerID="0" creatorID="0" nodeType="1066" template="1073"
sortOrder="0" createDate="2013-02-04T14:29:39"
updateDate="2013-02-07T11:08:27" nodeName="About"
urlName="about" writerName="Pete" creatorName="Pete"
path="-1,1050,1067" isDoc="">
<hideInNavigation>0</hideInNavigation>
</LandingPage>
</root>
What I need to do is filter these elements where hideInNavigation = 0
I have tried the following:
[@isDoc and @hideInNavigation ='0']
(I need the @isDoc attribute too) but realised this would only work if hideInNavigation
was an attribute of the LandingPage
tag so I tried
value['hideInNavigation'='0']
but this didn't seem to do anything either. After much searching for the answer, I haven't come up with anything so was wondering if it is possible
Upvotes: 0
Views: 287
Reputation: 6956
'hideInNavigation'='0'
compares the two strings 'hideInNavigation'
and '0'
, which are guaranteed to be different.
In the context of root, LandingPage[hideInNavigation=0]
would match the LandingPage element in your example.
Upvotes: 1
Reputation: 187
This XPath return all LandingPage with isDoc attribute empty and hideInNavigation element content is '0'
//LandingPage[@isDoc="" and hideInNavigation='0']
Upvotes: 0
Reputation: 101662
Supposing the current context was the <root>
element, you could select the LandingPages with hideInNavigation = 0 with:
LandingPage[hideInNavigation = '0']
If you would share your XSLT, I van give you more specific guidance on how to amend it for this particular case.
And was the @isDoc
test in your first example something you wanted? Do you want to filter LandingPages that have an isDoc
attribute and a hideInNavigation
value of 0?
Upvotes: 1