Can I define custom function in XSLT for XPath Builder?
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 22
- Joined: Tue Oct 17, 2017 5:05 pm
Can I define custom function in XSLT for XPath Builder?
Post by serioadamo97 »
I have some XPath expression in XPath Builder favorites .
These expression has a bit complicated and long, for example:
This xpath search starts in TableA.xml and find cross-reference in TableB.
It works fine, but the expression is too long. (I've simplified the expression for example only, the real expression is longer)
What I want to do is make $pdu as a common util function, which make my XPath expression shorter.
Is is possiable to define custom function in XSLT?
I created a util.xsl and add this file to Classpath of the framework, but it doesn't work.
Thanks.
These expression has a bit complicated and long, for example:
Code: Select all
let $contextNode := .,
$workspace := prov:getPluginWorkspace(),
$editorAccess := work:getCurrentEditorAccess($workspace, 0),
$pdu := editor-vars:expandEditorVariables('${pdu}', $editorAccess),
$global := doc(concat($pdu, '/TableB.xml'))
return $global//*[@name=$contextNode]
It works fine, but the expression is too long. (I've simplified the expression for example only, the real expression is longer)
What I want to do is make $pdu as a common util function, which make my XPath expression shorter.
Is is possiable to define custom function in XSLT?
I created a util.xsl and add this file to Classpath of the framework, but it doesn't work.
Thanks.
-
- Posts: 389
- Joined: Thu Jul 01, 2004 12:29 pm
Re: Can I define custom function in XSLT for XPath Builder?
Hello,
We do not have support to use an XSLT library for the XPath execution.
If you want you can create a Java extension function and then used it from the XPath Builder .
For this you need to do something like this:
Best Regards,
Octavian
We do not have support to use an XSLT library for the XPath execution.
If you want you can create a Java extension function and then used it from the XPath Builder .
For this you need to do something like this:
- create a class like the "ProjectRelativeResolver" added below
- then compile the class and it in a jar file
- copy the jar file in the "[OxygenInstallDir]/lib" folder.
- add a prefix-namespace mapping in the XPath options (ext - ro.sync.ecss.xpath.ProjectRelativeResolver), in the "XML / XSLT-FO-XQuery / XPath" options page
- Then you can use the function from the XPath builder to obtain the URL like this "ext:getURL("TableB.xml")
Code: Select all
package ro.sync.ecss.xpath;
import ro.sync.basic.util.URLUtil;
import ro.sync.exml.workspace.api.PluginWorkspace;
import ro.sync.exml.workspace.api.PluginWorkspaceProvider;
import ro.sync.exml.workspace.api.editor.WSEditor;
import ro.sync.util.editorvars.EditorVariables;
/**
* Resolves a relative URL to the project URL
*/
public class ProjectRelativeResolver{
/**
*
* @param relativePath The relative path.
* @return Returns an absolute path
*/
public static String getURL(String relativePath) {
PluginWorkspace pluginWorkspace = PluginWorkspaceProvider.getPluginWorkspace();
String currentEditedFileURL = null;
WSEditor currentEditorAccess = pluginWorkspace.getCurrentEditorAccess(PluginWorkspace.MAIN_EDITING_AREA);
if (currentEditorAccess != null) {
currentEditedFileURL = currentEditorAccess.getEditorLocation().toString();
}
String projectURL = EditorVariables.expandEditorVariables("${pdu}/", currentEditedFileURL);
return URLUtil.makeAbsolute(projectURL, relativePath);
}
}
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 22
- Joined: Tue Oct 17, 2017 5:05 pm
Re: Can I define custom function in XSLT for XPath Builder?
Post by serioadamo97 »
Hi tavy,
I create a Java extension function which return a node list like below:
And call ext:getNode() in XPath Builder, it works. (I can see all child nodes in XPath result view)
But when click a record in the Results View, it can not open D:/Global.xm and locate corresponding element.
How to return a value in Java extension function which can be located in XPath Results View?
Thanks.
I create a Java extension function which return a node list like below:
Code: Select all
public static NodeList getNode() throws SAXException, IOException, ParserConfigurationException {
DocumentBuilder db = ParserCreator.newDocumentBuilder();
Document doc = db.parse(new File("D:/Global.xml"));
return doc.getChildNodes();
}
But when click a record in the Results View, it can not open D:/Global.xm and locate corresponding element.
How to return a value in Java extension function which can be located in XPath Results View?
Thanks.
-
- Posts: 9451
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Can I define custom function in XSLT for XPath Builder?
Hi,
Octavian asked me to help you with this. Unfortunately once your custom Java method will be responsible with returning the nodes which are further used by the XPath expression, Oxygen can no longer localize the results. And we do not have a workaround for this.
Maybe instead of using our XPath view you could create separate XQuery files for each expression, at least in the XQuery files you could import common library XQuery files.
Regards,
Radu
Octavian asked me to help you with this. Unfortunately once your custom Java method will be responsible with returning the nodes which are further used by the XPath expression, Oxygen can no longer localize the results. And we do not have a workaround for this.
Maybe instead of using our XPath view you could create separate XQuery files for each expression, at least in the XQuery files you could import common library XQuery files.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 22
- Joined: Tue Oct 17, 2017 5:05 pm
Re: Can I define custom function in XSLT for XPath Builder?
Post by serioadamo97 »
But the results of executing separate XQuery files are not in XPath Result View.Radu wrote:Hi,
Maybe instead of using our XPath view you could create separate XQuery files for each expression, at least in the XQuery files you could import common library XQuery files.
Regards,
Radu
XPath's Results View is very useful, because we can click a record to locate and highlight its corresponding element, but XQuery Result View not has this feature.
So now, I can only copy very big XPath expression from XQuery files to XPath view every time

-
- Posts: 9451
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Can I define custom function in XSLT for XPath Builder?
Hi,
If you create an XQuery document and for it create a transformation scenario, in the "Output" tab of the transformation scenario config dialog you have the option to "Present as a sequence".
Regards,
Radu
If you create an XQuery document and for it create a transformation scenario, in the "Output" tab of the transformation scenario config dialog you have the option to "Present as a sequence".
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 22
- Joined: Tue Oct 17, 2017 5:05 pm
Re: Can I define custom function in XSLT for XPath Builder?
Post by serioadamo97 »
Hi,Radu wrote:Hi,
If you create an XQuery document and for it create a transformation scenario, in the "Output" tab of the transformation scenario config dialog you have the option to "Present as a sequence".
Regards,
Radu
I have checked "Present as a sequence" and the result sequence can display in the XQuery view. But I can't click it to navigate to the node.(I hope oxygen xml editor can open the xml file and locate to that element queried when I click the result record)
Thanks.
-
- Posts: 9451
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Can I define custom function in XSLT for XPath Builder?
Hi,
Indeed right now the nodes displayed after running an XQuery point to intervals in the output XML.
From what I looked in our code we could possibly add a contextual menu action on each result node to also open the original XML document from which the node was loaded and navigate to the node line and column.
I'll add an internal issue to look into this improvement, maybe we'll have some time after Oxygen 20.0 is released.
Regards,
Radu
Indeed right now the nodes displayed after running an XQuery point to intervals in the output XML.
From what I looked in our code we could possibly add a contextual menu action on each result node to also open the original XML document from which the node was loaded and navigate to the node line and column.
I'll add an internal issue to look into this improvement, maybe we'll have some time after Oxygen 20.0 is released.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 22
- Joined: Tue Oct 17, 2017 5:05 pm
Re: Can I define custom function in XSLT for XPath Builder?
Post by serioadamo97 »
That will be great, if Oxygen XML 2.0 support this feature.Radu wrote:Hi,
Indeed right now the nodes displayed after running an XQuery point to intervals in the output XML.
From what I looked in our code we could possibly add a contextual menu action on each result node to also open the original XML document from which the node was loaded and navigate to the node line and column.
I'll add an internal issue to look into this improvement, maybe we'll have some time after Oxygen 20.0 is released.
Regards,
Radu
In addition, I hope the I can right click the element in xml file, the editor will popup a context menu.
Then we can select a XQuery file (maybe has a history list which include recent used).
-
- Posts: 9451
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Can I define custom function in XSLT for XPath Builder?
Hi,
About this remark:
Regards,
Radu
About this remark:
So some kind of way to quickly execute an XQuery over the current XML document? Showing results which backmap to the XML document?In addition, I hope the I can right click the element in xml file, the editor will popup a context menu.
Then we can select a XQuery file (maybe has a history list which include recent used).
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 22
- Joined: Tue Oct 17, 2017 5:05 pm
Re: Can I define custom function in XSLT for XPath Builder?
Post by serioadamo97 »
XPath expression support context node, it is very convenient.
Because we can use mouse cursor position infomation in original xml, it is good if XQuery also support it.
Otherwise, we have to pass the parameter to XQuery manually.
Because we can use mouse cursor position infomation in original xml, it is good if XQuery also support it.
Otherwise, we have to pass the parameter to XQuery manually.
-
- Posts: 26
- Joined: Mon Mar 04, 2013 1:42 pm
Re: Can I define custom function in XSLT for XPath Builder?
Hi Radu,
.
Best regards,
Lionel
Yes I would like that a lotSo some kind of way to quickly execute an XQuery over the current XML document? Showing results which backmap to the XML document?

Best regards,
Lionel
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service