getting name and value of tag in an XML.

T

titusjava

Hello
I would like to know, is any easy way to getname of the XML tag and
value of the XML tag inside a <xsl:foreach> loop.

Thanks in advance
Titus
 
M

Martin Honnen

I would like to know, is any easy way to getname of the XML tag and
value of the XML tag inside a <xsl:foreach> loop.

XSLT uses XPath so check out an XPath reference for functions and you
will find functions like
local-name()
name()
namespace-uri()
to get the name or parts of it.
As for the value in terms of XSLT
<xsl:value-of select="." />
gives you what XSLT understands to be the value.
Or specify exactly what you understand to be the "value of an XML tag",
it is not clear what you are looking for.
 
T

titusjava

I am having an XML fragment like this

<data-items>
<element-name1>value 1</element-name1>
<element-name2>value 2</element-name2>
</data-items>

My requirement is given below

<forloop condition data-items/*>

// some function to get element-name1 and its value( value1),......
dynamically

</forloop>
I tried the function which you mentioned, but i think it work well with
node name not the element name.
 
M

Martin Honnen

I am having an XML fragment like this

<data-items>
<element-name1>value 1</element-name1>
<element-name2>value 2</element-name2>
</data-items>

My requirement is given below

<forloop condition data-items/*>

// some function to get element-name1 and its value( value1),......
dynamically

</forloop>


Use the functions/elements I suggested
<xsl:for-each select="data-items/*">
<div>
name is: <xsl:value-of select="name()" />
value is: <xsl:value-of select="." />
</div>
</xsl:for-each>
 

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
474,001
Messages
2,570,249
Members
46,846
Latest member
BettinaOsw

Latest Threads

Top