SteveMurphy Posted July 14, 2008 Share Posted July 14, 2008 Hi.I have the following xsl: <?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/Data/Parameter[IntegerValue=840]"> <xsl:value-of select="."/> </xsl:template></xsl:stylesheet> The xsl operates on the following xml: <?xml version="1.0" encoding="UTF-8"?><Data> <Parameter name="Age" nil="true"/> <Parameter name="Nationality"><IntegerValue>840</IntegerValue></Parameter> <Parameter name="Nationality"><IntegerValue>850</IntegerValue></Parameter> <Parameter name="Nationality"><IntegerValue>860</IntegerValue></Parameter> <Parameter name="NetWorth" nil="true"/></Data> I would expect the output to be a single value of 840, but instead, I get the following: 840 850 860 Can anyone tell me what I'm doing wrong?Thanks... Link to comment Share on other sites More sharing options...
boen_robot Posted July 15, 2008 Share Posted July 15, 2008 I think XSLT's default templates may be responsible for this. By default, all text nodes are value-of-ed, and if the root isn't matched, XSLT starts mathing everything.To cure what you have in particular, you can do: <xsl:template match="text()" /> To eliminate the default text node handling, or you can do: <xsl:template match="/"><xsl:apply-templates select="/Data/Parameter[IntegerValue=840]"/></xsl:template> In order to isolate the default text node handling. Link to comment Share on other sites More sharing options...
SteveMurphy Posted July 15, 2008 Author Share Posted July 15, 2008 thanks, boen_robot.Sounds like I need to get back up to speed on the default templates. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.