hi folks, i have the following xml: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href = "Sales.xsl" type = "text/xsl" ?> <SalesReport> <Company>XML.com</Company> <Period>2001-2002</Period> <Sales Region = "EU">50,000</Sales> <Sales Region = "NA">150,000</Sales> <Sales Region = "AV">10,000</Sales> </SalesReport> and the following xsl: ----------------------- <?xml version='1.0'?> <!-- FILE NAME main.xsl --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> <xsl:template match="/child::SalesReport/child::Sales"> <xsl:value-of select = "@Region"/> <xsl:value-of select = "."/>
</xsl:template> </xsl:stylesheet> it gives me the following result: _______________________________ XML.com2001-2002 EU50,000 NA150,000 AV10,000 this is contrary to what i had anticipated to get. i thought it would return me the values of Sales element and Region attribute that is, EU50,000 NA150,000 AV10,000 leaving off the first two elements. could someone explain me what's going on here? what am i missing as far as my understanding of XPath is concerned? thanks. himal [ October 19, 2002: Message edited by: Himal Chuli ]
You need to add a null template to suppress default processing of text elements: <xsl:template match="text()"/> Without this, XSLT will walk down from the root, past any node that doesn't otherwise match a template, and print out the string value of that node. [ October 19, 2002: Message edited by: Ron Newman ]
XSLT comes with the following default template built-in: <xsl:template match="text()"> <xsl:value-of select="."/> </xsl:template> which prints out the value of any text node it encounters. Often (maybe always), you don't want this, so you need to override it with the null template I posted in my earlier reply.