Content Completion Config with XSLT
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 87
- Joined: Fri Dec 19, 2003 6:02 pm
Content Completion Config with XSLT
hi.
i'm testing the new content completion configurations in v. 17. static configurations work flawlessly for me, but i am having trouble understanding how to implement the completion config with XSLT. The provided XSL template is not particularly useful without a corresponding XML file, because one can't test it directly, modify it etc. to see what effect one's changes have on the content completion.
so, i'm wondering if anybody has an XML (preferably TEI) file with a fully working XSLT content completion config that they could share for our hacking pleasure and for the sake of general enlightenment?
all best,
toma
i'm testing the new content completion configurations in v. 17. static configurations work flawlessly for me, but i am having trouble understanding how to implement the completion config with XSLT. The provided XSL template is not particularly useful without a corresponding XML file, because one can't test it directly, modify it etc. to see what effect one's changes have on the content completion.
so, i'm wondering if anybody has an XML (preferably TEI) file with a fully working XSLT content completion config that they could share for our hacking pleasure and for the sake of general enlightenment?
all best,
toma
-
- Posts: 87
- Joined: Fri Dec 19, 2003 6:02 pm
Re: Content Completion Config with XSLT
oh, and just to provide some more context:
my xml file contains dictionary entries like this (simplified here):
and i have cross references like this:
I'd like the content completion for the xr target to show entry xml:ids that contain the string "word"...
all this is in the same xml file on the filesystem...
my xml file contains dictionary entries like this (simplified here):
Code: Select all
<entry xml:id="XX.XX.word"> <form type="lemma">word</entry>
Code: Select all
<xr target=""> <ref>word</ref></xr>
all this is in the same xml file on the filesystem...
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Content Completion Config with XSLT
Hi,
Could you please clarify what you're referring to when you say "content completion configurations"?
What are you configuring (or expecting to configure) in Oxygen?
Another unclear aspect is if you need content completion when editing XSL, or are you maybe thinking of something else. Your example seems to indicate something else.
Regards,
Adrian
Could you please clarify what you're referring to when you say "content completion configurations"?
What are you configuring (or expecting to configure) in Oxygen?
Another unclear aspect is if you need content completion when editing XSL, or are you maybe thinking of something else. Your example seems to indicate something else.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 87
- Joined: Fri Dec 19, 2003 6:02 pm
Re: Content Completion Config with XSLT
sorry about not being clear enough.
i'm refering to http://www.oxygenxml.com/doc/versions/1 ... osals.html, which was introduced in v. 17.
i started by looking at the template file provided by oxygen which you get to when you select "Content Completion Configuration" when creating a new file. This configuration template is very well documented for static completions (in which all the suggestions are contained in the configuration file itself). Those I can work with without a glitch.
The same file contains a template of an XSL transformation (get_values_from_db.xsl) which can be used to create items for content completion — but that's where I am running into trouble. The configuration template suggests how to use XSL to create items suggestions for content completion, but is not a fully functioning example. Which is why I was asking if somebody had a working combo of an TEI/XML which contain some values, an XSL transformation to extract those values and an cc_value_config.xml which calls the XSL transformation to provide content completion.
All this — because I would like to implement content completion along the lines of the simplified example I included in my previous message.
I hope this clarifies things a bit.
all best,
Toma
i'm refering to http://www.oxygenxml.com/doc/versions/1 ... osals.html, which was introduced in v. 17.
i started by looking at the template file provided by oxygen which you get to when you select "Content Completion Configuration" when creating a new file. This configuration template is very well documented for static completions (in which all the suggestions are contained in the configuration file itself). Those I can work with without a glitch.
The same file contains a template of an XSL transformation (get_values_from_db.xsl) which can be used to create items for content completion — but that's where I am running into trouble. The configuration template suggests how to use XSL to create items suggestions for content completion, but is not a fully functioning example. Which is why I was asking if somebody had a working combo of an TEI/XML which contain some values, an XSL transformation to extract those values and an cc_value_config.xml which calls the XSL transformation to provide content completion.
All this — because I would like to implement content completion along the lines of the simplified example I included in my previous message.
I hope this clarifies things a bit.
all best,
Toma
-
- Posts: 87
- Joined: Fri Dec 19, 2003 6:02 pm
Re: Content Completion Config with XSLT
What I am about to say will invalidate some of the things I wrote above, which will make this into a very messy thread. but unfortunately, this forum is not letting me edit my own messages.
so.. i managed to get the XSLT content completion to work. now my cc_value_config has the following rule:
and cc_ref_targets.xsl looks like this:
the above pretty much mimics the usual code completion. when i am in a TEI file, where i have the following:
the code completion at @target will list xml:ids of all the entries. now, all those xml:ids look like this "XXX.XX.word", "XXX.XX.word2", "XXX.XX.someotherword" etc.
my question is whether i can use this mechanism to somehow filter all those entries and only show xml:ids that contain the string "word", e.g. "XXX.XX.word" and "XXX.XX.word2". in other words, is there any way i could pass the value of ref/rs/text() as a parameter to cc_ref_targets.xsl? is that at all possible or am I missing some more obvious solution?
so.. i managed to get the XSLT content completion to work. now my cc_value_config has the following rule:
Code: Select all
<match elementName="ref" elementNS="http://www.tei-c.org/ns/1.0" attributeName="target">
<xslt href="cc_ref_targets.xsl" useCache="false" action="replace"/>
</match>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:tei="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="2.0">
<xsl:param name="docPath">/path/to/my/xml/file.xml</xsl:param>
<xsl:template name="start">
<xsl:variable name="entries" select="doc($docPath)//*:entryFree"/>
<items action="replace">
<xsl:apply-templates select="$entries">
<xsl:sort select="tei:form[@lemma]/tei:orth/text()"/>
</xsl:apply-templates>
</items>
</xsl:template>
<xsl:template match="*:entryFree">
<item value="#{@xml:id}"></item>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<ref target=""> <rs>word</rs> </ref>
my question is whether i can use this mechanism to somehow filter all those entries and only show xml:ids that contain the string "word", e.g. "XXX.XX.word" and "XXX.XX.word2". in other words, is there any way i could pass the value of ref/rs/text() as a parameter to cc_ref_targets.xsl? is that at all possible or am I missing some more obvious solution?
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: Content Completion Config with XSLT
Post by alex_jitianu »
Hi,
You can access the context by using Java extension functions. Basically by calling our Java API from the XSLT. Here is how to treat the case when the user invokes Content Completion from the text page(if you also need the author page please let me know):
Best regards,
Alex
You can access the context by using Java extension functions. Basically by calling our Java API from the XSLT. Here is how to treat the case when the user invokes Content Completion from the text page(if you also need the author page please let me know):
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:tei="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:prov="java:ro.sync.exml.workspace.api.PluginWorkspaceProvider"
xmlns:work="java:ro.sync.exml.workspace.api.PluginWorkspace"
xmlns:editorAccess="java:ro.sync.exml.workspace.api.editor.WSEditor"
xmlns:textpage="java:ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage"
exclude-result-prefixes="xs xd"
version="2.0">
<xsl:param name="documentSystemID">/path/to/my/xml/file.xml</xsl:param>
<xsl:template name="start">
<xsl:variable name="workspace" select="prov:getPluginWorkspace()"/>
<xsl:variable name="editorAccess" select="work:getEditorAccess($workspace, xs:anyURI($documentSystemID), 0)"/>
<xsl:variable name="textpage" select="editorAccess:getCurrentPage($editorAccess)"/>
<!-- When this script is invoked the context is already in the attribute for which Content Completion is invoked -->
<xsl:variable name="xpathResult" select="textpage:evaluateXPath($textpage, 'xs:string(./parent::node()/*:rs/text())')"/>
<items>
<item>
<xsl:attribute name="value">
<xsl:value-of select="$xpathResult[1]"/>
</xsl:attribute>
</item>
</items>
</xsl:template>
</xsl:stylesheet>
Alex
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: Content Completion Config with XSLT
Post by alex_jitianu »
Hi Toma,
The idea is the same but the API differs a bit (please see the code below). I've also added an issue and in version 17.1 (hopefully) the XSLT script will receive an XPath expression that will identify the context element.
Best regards,
Alex
The idea is the same but the API differs a bit (please see the code below). I've also added an issue and in version 17.1 (hopefully) the XSLT script will receive an XPath expression that will identify the context element.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:tei="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:prov="java:ro.sync.exml.workspace.api.PluginWorkspaceProvider"
xmlns:work="java:ro.sync.exml.workspace.api.PluginWorkspace"
xmlns:editorAccess="java:ro.sync.exml.workspace.api.editor.WSEditor"
xmlns:saxon="http://saxon.sf.net/"
xmlns:textpage="java:ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage"
xmlns:authorPage="java:ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage"
xmlns:ctrl="java:ro.sync.ecss.extensions.api.AuthorDocumentController"
exclude-result-prefixes="xs xd"
version="2.0">
<xsl:param name="documentSystemID" as="xs:string"></xsl:param>
<xsl:template name="start">
<xsl:variable name="workspace" select="prov:getPluginWorkspace()"/>
<xsl:variable name="editorAccess" select="work:getEditorAccess($workspace, xs:anyURI($documentSystemID), 0)"/>
<xsl:variable name="pageID" as="xs:string" select="editorAccess:getCurrentPageID($editorAccess)"/>
<xsl:variable name="xpathResult">
<xsl:choose>
<xsl:when test="$pageID='Text'">
<xsl:variable name="textpage" select="editorAccess:getCurrentPage($editorAccess)"/>
<xsl:value-of select="textpage:evaluateXPath($textpage, 'xs:string(./parent::node()/*:rs/text())')[1]"/>
</xsl:when>
<xsl:when test="$pageID='Author'">
<xsl:variable name="authorPage" select="editorAccess:getCurrentPage($editorAccess)"/>
<xsl:variable name="caretOffset" select="authorPage:getCaretOffset($authorPage)"/>
<xsl:variable name="ctrl" select="authorPage:getDocumentController($authorPage)"/>
<xsl:variable name="contextNode" select="ctrl:getNodeAtOffset($ctrl, $caretOffset)"/>
<xsl:value-of select="ctrl:evaluateXPath($ctrl, 'xs:string(*:rs/text())', $contextNode, false(), false(), false(), false())[1]"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<items>
<item>
<xsl:attribute name="value">
<xsl:value-of select="$xpathResult"/>
</xsl:attribute>
</item>
</items>
</xsl:template>
</xsl:stylesheet>
Alex
-
- Posts: 87
- Joined: Fri Dec 19, 2003 6:02 pm
Re: Content Completion Config with XSLT
thank you so much for your help, alex. also for for adding a request to pass the context to XSLT in 17.1. i have a feeling that passing the context would make the content completion in cases like mine much snappier than the provided workaround with the Oxygen API. there is a noticeable lag with longer files that's not there if I rely strictly on the XSLT mechanism.
all best,
toma
all best,
toma
-
- Posts: 4
- Joined: Tue Oct 13, 2015 10:50 pm
Re: Content Completion Config with XSLT
Hello,
I noted that there was hope of simply passing the current context in through a parameter in version 17.1. Has this been implemented? I have a similar issue where I simply need the context node of the current caret positon, and wish to navigate the document. I'm not clear how to do that with the textpage:evaluateXPath expression provided which seems to return a string.
Thanks,
Dirk
I noted that there was hope of simply passing the current context in through a parameter in version 17.1. Has this been implemented? I have a similar issue where I simply need the context node of the current caret positon, and wish to navigate the document. I'm not clear how to do that with the textpage:evaluateXPath expression provided which seems to return a string.
Thanks,
Dirk
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: Content Completion Config with XSLT
Post by alex_jitianu »
Hello Dirk,
Yes, the feature will be present in v17.1 (to be released in a week or so). Some samples will be present in the topic Configuring the Proposals in the Content Completion Assistant.
will evaluate the expression in the context of the element or attribute on which the content completion is invoked for. It happens like this because the caret has to be there in order to request the proposals. If you are requesting the values for an attribute, the context is the attribute so will identify the parent element. The same situation is described in this blog (perhaps it will make things more clear): http://blog.oxygenxml.com/2015/07/contr ... art-2.html
Best regards,
Alex
Yes, the feature will be present in v17.1 (to be released in a week or so). Some samples will be present in the topic Configuring the Proposals in the Content Completion Assistant.
What you should know is that the callI'm not clear how to do that with the textpage:evaluateXPath expression provided which seems to return a string.
Code: Select all
textpage:evaluateXPath()
Code: Select all
./parent::*
Best regards,
Alex
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