I’m trying to write a simple .xslt to process .xml files. But I’ve been confused – why text in tags <tag>text</tag> has also been printed?
Please look at the example:
sample.xml
<source>
<employee>
<firstName>Joe</firstName>
<surname>Smith</surname>
</employee>
</source>
style.xsl
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="surname">
<div>
<xsl:value-of select="name()"/>
</div>
</xsl:template>
</xsl:stylesheet>
Why after calling: xsltproc style.xslt sample.xml I’m getting
Joe
<div>surname</div>
instead of
<div>surname</div>
only?
This is because
Joeis being handled by default. Text nodes are normally output by default. You need to override the default behavior.