Page 1 of 1

How to get the value of an element but not its children

Posted: Fri Jan 07, 2005 4:11 pm
by COM
Hi,

I would like to get the value of an element from a XML document without getting its children elements. It is possible to do it somehow?

Posted: Sat Jan 08, 2005 9:41 am
by george
Here it is an example. On the following XML

Code: Select all


<test> text1 <element>element text</element> text2</test>
the next XSL:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/test">
<xsl:apply-templates select="text()"/>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
will give you

Code: Select all


text1  text2
HTH,
George