Reputation: 13
I am new to XML and XSL, sorry to ask a silly question. How to locate data 'a' using XSL.
<A>
<B>b</B>
<C>c</C>
a
<D>d</D>
<E>e</E>
</A>
I have searched for answers and learned to locate b, c, d, e by using Xpath. When comes to data a, I failed. I tried to use path A but it displayed all data including b c a d e. Thanks for the help.
Upvotes: 1
Views: 67
Reputation: 338128
Several possibilities:
/A/text()
this selects all child text nodes of <A>
/A/text()[not(normalize-space() = '')]
this selects all non-empty text children of <A>
/A/text()[3]
this selects the '\n a\n '
node from your example specifically (note that there are whitespace-only text nodes that count as well!)
/A/C/following-sibling::text()[1]
this selects the '\n a\n'
node from your example specifically
//text()[following-sibling::* or preceding-sibling::*]
this selects all text nodes that have element siblings (i.e. mixed content)
Depends on how you look at it.
Upvotes: 1
Reputation: 89
Does something like //A/. not work? I'm no expert, but this should show the text for the A node only, I believe.
Upvotes: 0