Page 1 of 1

Content Completion Config with XSLT

Posted: Thu Jun 25, 2015 4:50 pm
by ttasovac
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

Re: Content Completion Config with XSLT

Posted: Thu Jun 25, 2015 5:00 pm
by ttasovac
oh, and just to provide some more context:

my xml file contains dictionary entries like this (simplified here):

Code: Select all

<entry xml:id="XX.XX.word"> <form type="lemma">word</entry>
and i have cross references like this:

Code: Select all

<xr target=""> <ref>word</ref></xr>
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...

Re: Content Completion Config with XSLT

Posted: Thu Jun 25, 2015 6:10 pm
by adrian
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

Re: Content Completion Config with XSLT

Posted: Thu Jun 25, 2015 6:27 pm
by ttasovac
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

Re: Content Completion Config with XSLT

Posted: Thu Jun 25, 2015 7:45 pm
by ttasovac
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:

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>
and cc_ref_targets.xsl looks like this:

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>
the above pretty much mimics the usual code completion. when i am in a TEI file, where i have the following:

Code: Select all

<ref target=""> <rs>word</rs> </ref>
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?

Re: Content Completion Config with XSLT

Posted: Fri Jun 26, 2015 10:34 am
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):

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>
Best regards,
Alex

Re: Content Completion Config with XSLT

Posted: Fri Jun 26, 2015 12:38 pm
by ttasovac
Dear Alex,

many thanks — this is really great.

I'd be very grateful if you could let me know how to accomplish the same for the Author Page as well.

All best,
Toma

Re: Content Completion Config with XSLT

Posted: Fri Jun 26, 2015 2:38 pm
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.

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>
Best regards,
Alex

Re: Content Completion Config with XSLT

Posted: Fri Jun 26, 2015 4:42 pm
by ttasovac
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

Re: Content Completion Config with XSLT

Posted: Wed Oct 14, 2015 4:20 pm
by DDubois
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

Re: Content Completion Config with XSLT

Posted: Thu Oct 15, 2015 9:36 am
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.
I'm not clear how to do that with the textpage:evaluateXPath expression provided which seems to return a string.
What you should know is that the call

Code: Select all

textpage:evaluateXPath()
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

Code: Select all

./parent::*
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