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

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

Fri Jan 07, 2005 4:11 pm

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: 2100

Sat Jan 08, 2005 9:41 am

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

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 2 guests