Jump to content

Help Debug xsl


SteveMurphy

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...