XPath for selecting the text of an attribute

P

pjvleeuwen

Hi all,

For many of you this may be childishly simple, but the following
problem keeps me wondering for almost two hours, so I hope any of you
could point out what it is that I am doing wrong.

Consider the following simple XML: <?xml version="1.0"?
<rootE><tagA>valueA</tagA><tagB attrB1="attrValueB1"
attrB2="attrValueB2"/> said:
<tagCCB>60</tagCCB><tagCCC/></tagCC><tagCD/><tagCE/></tagC></rootE>

Now I want to read the value "attrValueB2" so I tried writing a
regular expression for it. I know that the following selects the
attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
@attrB2
But I cant seem to select the value of this attribute. I get an empty
string when quering /rootE/tagB/@attrB2/text()

ANY suggestions? I cant see what I'm doing wrong. Everything seems to
be fine in comparison with the tutorials I have seen and I tried all
the lexical variations / alterations I could think of.

Many thanks in advance for any suggestions!

Cheers,
Paul
 
M

Martin Honnen

Now I want to read the value "attrValueB2" so I tried writing a
regular expression for it. I know that the following selects the
attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
@attrB2
But I cant seem to select the value of this attribute. I get an empty
string when quering /rootE/tagB/@attrB2/text()

Attributes in the XPath data model don't have any text child nodes.
Simply use
/rootE/tagB/@attrB2
to select the attribute, then you would get the value in a way depending
on the host language e.g. in XSLT with
<xsl:value-of select="/rootE/tagB/@attrB2"/>
 
B

Bjoern Hoehrmann

* (e-mail address removed) wrote in comp.text.xml:
Now I want to read the value "attrValueB2" so I tried writing a
regular expression for it. I know that the following selects the
attribute (nicely highlighted by the Liquid XML Studio): /rootE/tagB/
@attrB2
But I cant seem to select the value of this attribute. I get an empty
string when quering /rootE/tagB/@attrB2/text()

Use "string(/rootE/tagB/@attrB2)" though string() will be used
implicitly in many cases and is consequently rarely necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top