简体   繁体   中英

Sharing XPaths between XSLT and Java Classes

Is there a common solution for sharing XPaths between XSLT (ie for web pages, HTML reports etc) and Java classes (ie Xml node objects etc)? For example, a standalone XML configuration file of some type that holds all XPaths which can then be read by both an XSLT style sheet and a Java class for various purposes?

This would be handy when the schema for the XML data that I am parsing data from changes (the schema is a standardised one used by many organisations that changes frequently) - I could then just make a change to this single source of truth and have it reflect in both the XSLT and Java classes when the schema is updated.

I guess my limited experience with XSLT is showing here. A better question might be: Can you read in external files (and if so, which types?) and assign values from these external files as variables in XSLT?

Thanks!

Many XSLT processors have an xx:evaluate() extension which can be used to read XPath expressions from a file and execute them. It can be a useful technique if the XPath expressions encapsulate business rules (eg calculation of price discounts) which are maintained separately from the stylesheet itself.

Another technique is to encapsulate the XPath expressions in a function library (could be Java, could be XQuery) in such a way that the functions can be called from either Java or XSLT. Details depend on the actual technology you are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM