XML:
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
<location>DL</location>
</book>
<book category="children">
<title lang="es">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
<location>UP</location>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
<location> DL</location>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
<location>dl </location>
</book>
<category>web</category>
</bookstore>
XPath expression:
string(/bookstore/book/@category)
The above XPath expression is returning only the value of the first attribute under book element:
cooking
Expected output:
cooking
children
web
web
I want my XPath expression to return the string value of all the attributes of book element. I referred several posts but I couldn't find onw in which I could get all the attribute values.
xpath-2.0
tag. In XPath 2.0, your expression would produce an error because thestring()
function takes only a single item as its argument. – michael.hor257k<xsl:value-of select="/bookstore/book/@category"/>
will display"cooking children web web"
. In XSLT 1.0, you can select all categories using the same expression and use this selection for comparison - butxsl:value-of
(and other expressions, such asstring()
) will return only the first one of these. -- Please edit your question to clarify what exactly you want to do, incl. the expected output. – michael.hor257k