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.
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/
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.
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:
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.
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.
> 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.
Thank you for your help.
M.