473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XPath for selecting the text of an attribute

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"/><tagC><tagCA/><tagCB/><tagCC><tagCCA/><tagCCA/
><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
Jun 27 '08 #1
3 11721
pj********@gmail.com wrote:
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"/>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
* pj********@gmail.com 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.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 27 '08 #3
You where both right. Thank you very much. This clarifies a lot.
Cheers,
Paul

On May 19, 1:08 pm, Bjoern Hoehrmann <bjo...@hoehrmann.dewrote:
* pjvleeu...@gmail.com 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.
--
Björn Höhrmann · mailto:bjo...@hoehrmann.de ·http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 ·http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 ·http://www.websitedev.de/
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Vince C. | last post by:
Hi, all. I'd like to know if there's a way to simplify writing attribute values in XSLT. The case is the following: <xsl:template ...> <div id="{ if (@id) @id else generate-id() }">Div...
2
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the...
2
by: Mike Kamermans | last post by:
I'm having some trouble using text() in an xsl:value-of xpath. I have the following xml: .... <graphemes> <grapheme>1</grapheme> <grapheme>2</grapheme> <grapheme>3</grapheme> </graphemes>...
9
by: Tjerk Wolterink | last post by:
Hello, suppose i have a dom like this: <a> - <b> - <b> - <d> - </b> - <c>
4
by: RelaxoRy | last post by:
Is there any way to stop someone getting their mouse and selecting text on a page (without making the text an image of course). Is it possible to trap and stop click-and-drag functionality from...
1
by: Cheryl | last post by:
I have problems selecting the attribute when I use the SelectNode function. <book> <title store='7456' >Nutshell</title> <author id='1'>Drayton</author> <xauthor publish = "1" publishtime =...
1
by: serge calderara | last post by:
Dear all, I have a datagrid which is bind to a databse table. One field of that table contains a filename. What I ma trying to do is to display the content of a cell to be an icon when the...
2
by: bignass04 | last post by:
Hi all, I'm a newbie to XSLT working on my first project with it and I'm stuck on a particular thing. I want to create a document that will write the PCDATA from a given <Lineelement, then, in...
1
by: =?ISO-8859-1?Q?Une_B=E9vue?= | last post by:
my xml fragment : <select id='aId'> <option>option 1</option> <option>option 2</option> <option>---?---</option> <option>option n + 1</option> <option>option n + 2</option>
2
by: Grant Merwitz | last post by:
Hi, i'm not sure if this is the appropriate topic. But here goes: I am currently bulding a site menu from a xml file. I have an attribute that indicates whether an option is active or not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.