Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Veryfing XPath expressions inside XSTL document

4 views
Skip to first unread message

Marcin Ochocki

unread,
Dec 11, 2009, 6:02:35 AM12/11/09
to
Hi,

I have following situation:
1. Set of classes compiled to classes.dll
2. classes.xsd generated from classes.dll using xsd.exe
3. Set of XSLT documents with a lot of XPath expressions referencing
types from classes.dll

...and following problem:
When someone changes type A that is referenced in XSLT document (for
example renames a field) the classes.xsd is regenerated and there is
no build issues in my project. Furthermore even xslt transformations
are performed without errors (only the final pdf does not look like
expected).

Is there any way to check whether XPath expressions are still valid. I
would like to include such a check in build process.

M.

Martin Honnen

unread,
Dec 11, 2009, 7:03:15 AM12/11/09
to

I am not sure I understand what you call a "valid XPath expression". If
it is syntactically correct then e.g. /root/foo/bar is a valid
expression, whether the XML input you want to use that XPath against
does have a 'bar' element or not does not matter, at least not in XPath 1.0.

The only issue that I can think of: depending on how you write your XSLT
you could consider to insert a template matching all not otherwise
processed elements and output some warning if that happens.


--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

Marcin Ochocki

unread,
Dec 11, 2009, 10:25:42 AM12/11/09
to
By valid I mean 'still existing'. For example if I have a class
class Customer
{
public string name;
//....
}

and in xslt I have XPath expression Customer/name.

Then someone changes "public string name" to "public string CustName".
Project still compiles and there is no schema validation errors (I
perform xsd checks before transformation), as xsd is generated form
the code. But customer name is not shown on the printout.

M.

Marcin Ochocki

unread,
Dec 11, 2009, 10:26:11 AM12/11/09
to
By valid I mean 'still existing'. For example if I have a class
class Customer
{
public string name;
//....
}

and in xslt I have XPath expression Customer/name.

Then someone changes "public string name" to "public string CustName".
Project still compiles and there is no schema validation errors (I
perform xsd checks before transformation), as xsd is generated form
the code. But customer name is not shown on the printout.

M.

On 11 Gru, 13:03, Martin Honnen <mahotr...@yahoo.de> wrote:

Martin Honnen

unread,
Dec 11, 2009, 11:39:27 AM12/11/09
to
Marcin Ochocki wrote:
> By valid I mean 'still existing'. For example if I have a class
> class Customer
> {
> public string name;
> //....
> }
>
> and in xslt I have XPath expression Customer/name.
>
> Then someone changes "public string name" to "public string CustName".
> Project still compiles and there is no schema validation errors (I
> perform xsd checks before transformation), as xsd is generated form
> the code. But customer name is not shown on the printout.

I don't think there is an easy way with XSLT/XPath 1.0. You would need
to implement your own checks or implement your own solution that ensures
your XSLT has the correct element and attribute names matching the
definitions in your schema.

If you move to schema aware XSLT 2.0 as implemented by Saxon 9
(http://www.saxonica.com/) then you might get assistance from the XSLT
processor warning you that certain expressions will never find nodes
with a certain input schema present.

Marcin Ochocki

unread,
Dec 16, 2009, 6:10:43 AM12/16/09
to
Hi,

I downloaded saxonhe9-2-0-3n.zip, changed <xsl:stylesheet
version="1.0" to <xsl:stylesheet version="2.0" in my xslt file and ran
bin\Transform.exe tool.
But the result for the changed XPath expression (I renamed a field -
so it does not exist in xml) is the same - xslt engine just renders
empty field.

So does XSLT2.0 (Saxon?) really can validate misspelled XPath
expressions? Is it possible?

M.

Martin Honnen

unread,
Dec 16, 2009, 7:23:15 AM12/16/09
to
Marcin Ochocki wrote:

> I downloaded saxonhe9-2-0-3n.zip, changed <xsl:stylesheet
> version="1.0" to <xsl:stylesheet version="2.0" in my xslt file and ran
> bin\Transform.exe tool.
> But the result for the changed XPath expression (I renamed a field -
> so it does not exist in xml) is the same - xslt engine just renders
> empty field.
>
> So does XSLT2.0 (Saxon?) really can validate misspelled XPath
> expressions? Is it possible?

For schema aware processing you need Saxon-PE or Saxon-EE I think. And
then you need to use more steps than simply changing the version
attribute, you need to import any schema you want to validate against.
I am not familiar with the details of using Saxon for schema aware
processing, you will need to read the documentation (e.g.
http://www.saxonica.com/documentation/sourcedocs/validation.html) and if
you have any questions specific to Saxon then I think it is best you
raise them on the Saxon help mailing list
http://lists.sourceforge.net/lists/listinfo/saxon-help.

Marcin Ochocki

unread,
Dec 16, 2009, 8:10:01 AM12/16/09
to
On 16 Gru, 13:23, Martin Honnen <mahotr...@yahoo.de> wrote:
> Marcin Ochocki wrote:
> > I downloaded saxonhe9-2-0-3n.zip, changed <xsl:stylesheet
> > version="1.0" to <xsl:stylesheet version="2.0" in my xslt file and ran
> > bin\Transform.exe tool.
> > But the result for the changed XPath expression (I renamed a field -
> > so it does not exist in xml) is the same - xslt  engine just renders
> > empty field.
>
> > So does XSLT2.0 (Saxon?) really can validate misspelled XPath
> > expressions? Is it possible?
>
> For schema aware processing you need Saxon-PE or Saxon-EE I think. And
> then you need to use more steps than simply changing the version
> attribute, you need to import any schema you want to validate against.
> I am not familiar with the details of using Saxon for schema aware
> processing, you will need to read the documentation (e.g.http://www.saxonica.com/documentation/sourcedocs/validation.html) and if

> you have any questions specific to Saxon then I think it is best you
> raise them on the Saxon help mailing listhttp://lists.sourceforge.net/lists/listinfo/saxon-help.

>
> --
>
>         Martin Honnen --- MVP XML
>        http://msmvps.com/blogs/martin_honnen/

Thank you for your help.

M.

0 new messages