I am trying to do a match for two scenarios:
So the XSLT is:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="record[translate(employeeNumber, 'abcdefghijklmnopqrstuvwxyzABCDEFGHILKLMNOIPQRSTUVWXYZ!£$%^', '')]"/>
<xsl:template match="record[string-length(employeeNumber) < 9]"/>
</xsl:stylesheet>
Test Data is:
<?xml version="1.0" encoding="UTF-8"?>
<request>
<records>
<record>
<employeeNumber>12345678</employeeNumber>
</record>
<record>
<employeeNumber>1234567A</employeeNumber>
</record>
<record>
<employeeNumber>12345678A</employeeNumber>
</record>
<record>
<employeeNumber>123456789</employeeNumber>
</record>
</records>
</request>
This is what should be returned:
<?xml version="1.0" encoding="UTF-8"?>
<request>
<records>
<record>
<employeeNumber>1234567A</employeeNumber>
</record>
<record>
<employeeNumber>12345678A</employeeNumber>
</record>
<record>
<employeeNumber>123456789</employeeNumber>
</record>
</records>
</request>
However as i said in Oxygen i am getting the error:
Severity: warning
Description: Ambiguous rule match for /request[1]/records[1]/record[1]
Matches both "record[string-length(employeeNumber) < 9]" on line 13 of file:/C:/Users/mdown/Desktop/Untitled21.xsl
and "record[translate(employeeNumber, 'abcdefghijklmnopqrstuvwxyzABCDEFGHILKLMNOIPQRSTUVWXYZ!£$%^', '')]" on line 12 of file:/C:/Users/mdown/Desktop/Untitled21.xsl
The reason for this is because it is matching both rules, however this should not be a problem. How would i alter the XSLT to support these options.
It looks to me as if you are getting a warning, not an error. If you want to avoid the warning then decide which template should have higher priority and set that e.g. <xsl:template match="foo" priority="5"/>
as needed.
The XSLT specification says that it is a "recoverable error" if a node matches more than one template rule with the same priority. Implementations are allowed to ignore the error and choose whichever template comes last, or they are allowed to treat it as a hard error. Saxon allows either of these options to be selected by a command line parameter, but by default it chooses a middle options which is to report a warning and carry on.
I would recommend that when you get this warning, you examine the two rules and decide which of them you want to take priority. Then give both rules explicit priority attributes so there is no ambiguity.
I am not sure if this will work, but try adding the opposite check on the length to the first template match
<xsl:template match="record
[translate(employeeNumber, 'abcdefghijklmnopqrstuvwxyzABCDEFGHILKLMNOIPQRSTUVWXYZ!£$%^', '')]
[string-length(employeeNumber) >= 9]"/"/>
<xsl:template match="record[string-length(employeeNumber) < 9]"/>
It is a bit of duplicate coding, but they should now not match the same record.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With