Project

Profile

Help

XPath 2.0 functions not found from code

Added by Anonymous over 15 years ago

Legacy ID: #6538187 Legacy Poster: Jeroen Kransen (jkransen)

When I run a transformation from Java code, some XPath 2.0 functions seem not to be recognised. The ErrorListener gives these errors: ERROR: An error occurred matching pattern {*[local-name-from-QName(@scheme)='PostcodeHuisnummer' and namespace-uri-from-QName(@scheme)='http://standaarden.overheid.nl/owms/terms/']}: ; SystemID: file:/D:/ictu/pmtonline/apache-tomcat-5.5.17/webapps/owmsvalidator/schematron/vac_sa.xsl; Line#: 280; Column#: -1 The functions local-name-from-QName and namespace-uri-from-QName seem to cause problems. Without these, the matches are made. When the same transformation is run from command line, there are no problems. We run in schema-aware mode. I instantiate the Source of the transformation from a file on the local file system, the System ID seems to be correct: file:/D:/ictu/pmtonline/apache-tomcat-5.5.17/webapps/owmsvalidator/schematron/vac_sa.xsl I verified that we use a schema aware transformation. I got no version warnings, even though I did not turn these off.


Replies (11)

Please register to reply

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6538282 Legacy Poster: Michael Kay (mhkay)

The most likely explanation is that you are not running Saxon. Use system-property('xsl:vendor') to check this. If you're using JAXP and your stylesheet uses XSLT 2.0, it's best to instantiate the Saxon TransformerFactory directly: "new net.sf.saxon.TransformerFactoryImpl()" or "new com.saxonica.validate.SchemaAwareTransformerFactory()" instead of TransformerFactory.newInstance(). Apart from anything else, this saves an expensive search of the classpath.

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6538347 Legacy Poster: Michael Kay (mhkay)

On the other hand, this DOES look like a Saxon error message. So another explanation would be that @scheme is not an xs:QName (for example, because the attribute is untyped, which would happen if no validation was done). The other factor is that errors in matching patterns are classified as recoverable errors, and the way that Saxon handles them will depend on the recovery policy which is set as a configuration option. This might vary between your command line and your Java application.

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6539065 Legacy Poster: Jeroen Kransen (jkransen)

Thank you for your prompt response. I already do instantiate com.saxonica.SchemaAwareTransformerFactory directly, and I verified the Saxon version (besides the fact that it is indeed in schema aware mode): Saxon version: Saxon-SA 9.1.0.5J from Saxonica Do you mean with untyped attribute that it does not belong to a namespace? Indeed it does not. Then again, nor does it with the command line translation. When I use the schema aware Translator, and I set the schema validation mode to strict or lax, I check the value ct.getConfiguration().isSchemaAware(Configuration.XSLT). It returns true. Is there a way to check whether validation was done? With "timing" information on, I see a whole list of *.xsd files being loaded successfully.

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6539173 Legacy Poster: Michael Kay (mhkay)

I always do something like this at the start of a schema-aware stylesheet: <xsl:template match="/"> <xsl:message terminate="yes">Input must be a validated purchase-order</xsl:message> </xsl:template> <xsl:template match="document-node(schema-element(po:purchase-order))"> .. process the validated purchase order .. </xsl:template> This ensures that if someone accidentally supplies an input document without validation, the error is caught immediately. You can also use saxon:type-annotation() to display the type annotation on the outermost element node.

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6539185 Legacy Poster: Michael Kay (mhkay)

>Do you mean with untyped attribute that it does not belong to a namespace? No, I mean that its type annotation is xs:untypedAtomic rather than xs:QName. This is the only explanation I can think of for the functions such as namespace-uri-from-QName() failing with a dynamic error.

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6550802 Legacy Poster: Jeroen Kransen (jkransen)

Indeed I get a message that the input was not validated. Now I wonder how this is possible. In the construction arg of the com.saxonica.SchemaAwareTransformerFactory, I pass a com.saxonica.validate.SchemaAwareConfiguration with setSchemaValidationMode(1) or (2), lax or strict. Why is still no validation taking place?

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6551212 Legacy Poster: Michael Kay (mhkay)

Setting the validation mode in the Configuration establishes a default setting, but there are ways of overriding it for specific documents (you might want to validate some documents and not others). So I think we need to look at the detail to see how this particular document was processed. (Actually, this has become quite a messy area, because there are quite a number of ways of saying how you want documents to be parsed at different points in the system, and it's not always clear how these options interact.)

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6551484 Legacy Poster: Jeroen Kransen (jkransen)

How can I explicitly validate a document? With the Transformer that I instantiated as stated before, I basically do: document = someDocumentBuilder.parse(content); Source source = new DOMSource(document); transformer.transform(source, result); In this setting, how can the value for validationMode deviate from the default? How can I explicitly set it?

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6551687 Legacy Poster: Michael Kay (mhkay)

I think it's because you are using a DOMSource. This means Saxon isn't in control of the parsing, so the switch to do validation is never examined on this path. Using a DOMSource is also very inefficient (Saxon is much faster transforming its own tree model than transforming a DOM, sometimes by a factor of ten). If you switch to a StreamSource or SAXSource and let Saxon control the parsing and tree building, all should be well.

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6551826 Legacy Poster: Jeroen Kransen (jkransen)

In some situations I may get away with using the StreamSource, but sometimes I do need the Document for other purposes. Is there a way to validate it in that case?

RE: XPath 2.0 functions not found from code - Added by Anonymous over 15 years ago

Legacy ID: #6553112 Legacy Poster: Michael Kay (mhkay)

When Saxon is processing a DOM it always treats it as untyped. So if you are starting with data in a DOM, you will need to copy it into a Saxon tree, applying schema validation as you go. Looking at the code of Controller.transform(), it seems to be intended to recognize this situation and do the copy automatically, but it's not getting the logic quite right. The way around this that should work is to wrap the DOMSource in an AugmentedSource that specifies the processing options required: DOMSource dom; AugmentedSource as = AugmentedSource.makeAugmentedSource(dom); as.setValidationMode(Validation.STRICT); as.setWrapDocument(false); transformer.transform(as, result) Michael Kay http://www.saxonica.com/

    (1-11/11)

    Please register to reply