File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Harvesting XPATHs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Harvesting XPATHs " Watch "Harvesting XPATHs " New topic
Author

Harvesting XPATHs

Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Here's something to pick your brain. I need to parse an XSL style sheet and harvest all the XPATHs. Since XSLs are XMLs anyway, this shouldn't be a problem.

Questions -

1. Is there a tool that does this already?

2. Since my style sheet can < xsl:include > other style sheets, I need a way for the parser to resolve the includes and include the actual content in the final DOM. Standard out-of-the-box DOM parser functionality simply reports the < xsl:include > as just another node.

Thanks!
[ January 18, 2006: Message edited by: Ajith Kallambella ]

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

have you checked out XmlSpy

It's a great tool -- does a lot of stuff... definitely might do what you're looking for.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
But I need to do this at run time, not at design time.

Sorry for making this unclear, but the requirement is this - I will be handed over an XSL at run time, and I should scrape it for XPATH expressions. Eventually these expressions will be evaluated on the DOM tree using Xalan XPathAPI to capture the nodes referred by the expressions.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Shouldn't be too hard. First identify all the possible places where an XPath expression can appear in an XSLT document. Then write another XSLT that looks in all those places, and have it output everything you think might be XPath. You can handle xsl:include and xsl:import via the document() function.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by Ajith Kallambella:
Eventually these expressions will be evaluated on the DOM tree using Xalan XPathAPI to capture the nodes referred by the expressions.
However since XPath expressions are relative to a context node, and you won't be capturing the context node when you extract them from the XSLT document, this feature may not be as useful as the designer thought. Unless all the XPath expressions are constrained to start with the root element.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
[Well I started something but realized that would'nt work...]

I can only think of "grep" for some common pattern (contains /, maybe). This also is not a complete solution, but brain-stoming.
Thanks.

- m

ps: Ajith, if you have a working solution, maybe you can share it here.


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
 
subject: Harvesting XPATHs