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

Here should go questions about transforming XML with XSLT and FOP.
COM
Posts: 2
Joined: Fri Jan 07, 2005 4:02 pm

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

Post 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?
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
Post Reply