|
top
|
 Subject: parsing error using Author: (Deleted User) Date: 21 Nov 2005 12:46 PM
|
Allen,
You have encountered a subtle difficulty when trying to compare nodesets to strings.
This is your sample data:
<?xml version="1.0"?>
<Data xmlns:xfdf="http://ns.adobe.com/xfdf-transition/">
<P3>
<AppendixA>
<ProductNo>
<field>KRA213D</field>
<field>KRL1024PC</field>
</ProductNo>
</AppendixA>
</P3>
</Data>
In your .xslt file, you have
<xsl:for-each select="*/AppendixA/ProductNo">
<xsl:if test="substring(field,1,6) = 'KRL761'">
<xsl:value-of select="1"/>
</xsl:if>
<xsl:if test="substring(field,1,7) = 'KRL7002'">
<xsl:value-of select="1"/>
</xsl:if>
etc…
The xsl:for-each executes once for each ProductNo element, NOT once for each ProductNo/field.
The way you have written the .xslt, field is not a single string value, but a nodeset containing all the field nodes in the ProductNo element.
Now, in XPATH, an expression like nodeset=’string’ is defined to be true if ANY node in nodeset matches ‘string’, so your program works pretty well as long as you stick to simple equality. However, in XPATH, the substr(…) function is defined differently. If its first argument is a nodeset, substr takes the string value of the FIRST node in the nodeset and discards the rest. Since KRL1024PC is not the first node in the nodeset, substr(...) = ‘KRL1024’ will never match properly.
I don’t know whether you intended to use nodesets, or if it was an accidental error, but here is a suggestion on how to fix the program:
<xsl:for-each select="*/AppendixA/ProductNo/field">
<xsl:if test="substring(.,1,6) = 'KRL761'">
<xsl:value-of select="1"/>
</xsl:if>
<xsl:if test="substring(.,1,7) = 'KRL7002'">
<xsl:value-of select="1"/>
</xsl:if>
etc…
I hope this clarifies the issue,
- clyde
|
|
|
|