[oXygen-user] XPath-validation in non-XSLT-files
George Cristian Bina
Mon Oct 30 08:41:37 CST 2006
Dear Theun,
The XSLT validation performed by oXygen tries to create a Transformer
object out of the edited XSLT stylesheet. This performs a more powerful
checking of the XSLT document (compared with for instance a validation
against a specific schema) and the XSLT processor used for validation
reports also XPath errors. The XPath content completion that oXygen
offers on XSLT files is strongly related with the fact that the edited
file is an XSLT document. From the associated transformation scenario we
identify the document that can be the input for the stylesheet and we
determine possible elements and attributes from there, we also take into
account the XSLT instruction that change the context in order to offer
correct completion proposals.
As you see in the above description, both the validation and the content
completion cannot be de-coupled from the XSLT editor immediately so the
answer is no, you cannot have XPath validation and XPath content
completion in the XML editor.
However, there are a couple of things you can do.
You can write a stylesheet to extract your XPath expression and generate
as output another stylesheet that contains those XPath expressions
associated eventually with information to easily identify where those
XPath expression were extracted from. Then validate the generated
stylesheet and if you find problems use that identification information
to locate the expression in the original document.
Another possibility is to take advantage of the fact that oXygen
supports XPath 2.0 for Schematron using Saxon 8 and create an XML Schema
with embedded Schematron rule and use the saxon:expression function to
test that a specific value is an XPath expression, you can find below an
example of this approach.
XML Schema with embedded Schematron rules test.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:appinfo>
<ns xmlns="http://www.ascc.net/xml/schematron"
uri="http://saxon.sf.net/" prefix="saxon"/>
</xs:appinfo>
</xs:annotation>
<xs:element name="test">
<xs:complexType>
<xs:sequence>
<xs:element ref="xpath" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="xpath">
<xs:annotation>
<xs:appinfo>
<pattern xmlns="http://www.ascc.net/xml/schematron"
name="testXPath">
<rule context="xpath">
<assert test="saxon:expression(@expression)">Invalid XPath
expression!</assert>
</rule>
</pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:attribute name="expression" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
test.xml
<?xml version="1.0" encoding="UTF-8"?>
<?oxygen SCHSchema="test.xsd"?>
<test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<xpath expression="test;"/>
<xpath expression="test"/>
<xpath expression="test"/>
</test>
reported error:
SystemID: E:\george\test\p2\test.xml
Description: Static error in XPath expression supplied to
saxon:expression: XPath syntax error at char 4 in {test;}:
Unexpected token ";" beyond end of expression
The problem is that there is no tracing from the error to the source and
all you can do is to get the expression between curly braces in this
case test; and find it in your document.
Hope that helps,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Theun Fleer wrote:
> Hello,
>
> When editing XLST-files in oXygen7.2 on WinXP the XPath-expressions in
> the "select" and "match" attributes can be validated. When typing an
> incorrect XPath-expression, a wavy yellow line is shown, and an error
> description at the bottom of the screen; "content completion" is also an
> option.
>
> We are currently editing non-XSLT-files: a custom XML format with a
> custom namespace in which we must edit a lot of long XPath-expressions.
> We would like the same validation options as in the XLST-files... is
> this possible, and how?
>
> Kind regards, and keep up the good work!
>
> Theun Fleer
> Daidalos BV, The Netherlands
>
>
> Drs. T. Fleer
> Consultant
> GSM: +31 (0)6 40 58 50 27
>
>
>
> Daidalos BV
> Source of Innovation
> Hoekeindsehof 1-4
> 2665 JZ Bleiswijk
> Tel.: +31 (0) 10 850 1200
> Fax: +31 (0) 10 850 1199
> www.daidalos.nl
> KvK 27164984
>
>
> De informatie - verzonden in of met dit emailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend.
> _______________________________________________
> oXygen-user mailing list
>
> http://www.oxygenxml.com/mailman/listinfo/oxygen-user
More information about the oXygen-user
mailing list