<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>About oXygen XML Editor</title>
</head>
<body>
<style type="text/css">

                        h1 a:hover {background-color:#888;color:#fff ! important;}

                        div#emailbody table#itemcontentlist tr td div ul {
                                        list-style-type:square;
                                        padding-left:1em;
                        }
        
                        div#emailbody table#itemcontentlist tr td div blockquote {
                                padding-left:6px;
                                border-left: 6px solid #dadada;
                                margin-left:1em;
                        }
        
                        div#emailbody table#itemcontentlist tr td div li {
                                margin-bottom:1em;
                                margin-left:1em;
                        }


                        table#itemcontentlist tr td a:link, table#itemcontentlist tr td a:visited, table#itemcontentlist tr td a:active, ul#summarylist li a {
                                color:#000099;
                                font-weight:bold;
                                text-decoration:none;
                        }       

                        img {border:none;}


                </style>
<div xmlns="http://www.w3.org/1999/xhtml" id="emailbody" style="margin:0 2em;font-family:Georgia,Helvetica,Arial,Sans-Serif;line-height:140%;font-size:13px;color:#000000;">
<table style="border:0;padding:0;margin:0;width:100%">
<tr>
<td style="vertical-align:top" width="99%">
<h1 style="margin:0;padding-bottom:6px;">
<a style="color:#888;font-size:22px;font-family:Arial,Helvetica,Sans-Serif;font-weight:normal;text-decoration:none;" href="http://blog.oxygenxml.com/" title="(http://blog.oxygenxml.com/)">About oXygen XML Editor</a>
</h1>
</td>
<td width="1%" />
</tr>
</table>
<hr style="border:1px solid #ccc;padding:0;margin:0" />
<table id="itemcontentlist">
<tr xmlns="">
<td style="margin-bottom:0;line-height:1.4em;">
<p style="margin:1em 0 3px 0;">
<a name="1" style="font-family:Arial,Helvetica,Sans-Serif;font-size:18px;" href="http://feedproxy.google.com/~r/AboutOxygenXmlEditor/~3/NE2VjDi24KA/controlled-attribute-values-part-2.html?utm_source=feedburner&utm_medium=email">Controlled Attribute Values (Part 2 - Advanced) </a>
</p>
<p style="font-size:13px;color:#555;margin:9px 0 3px 0;font-family:Georgia,Helvetica,Arial,Sans-Serif;line-height:140%;font-size:13px;">
<span>Posted:</span> 17 Jul 2015 03:42 AM PDT</p>
<div style="margin:0;font-family:Georgia,Helvetica,Arial,Sans-Serif;line-height:140%;font-size:13px;color:#000000;"><div class="body">    <p class="p">As already presented in <strong class="ph b"><a class="xref" href="http://blog.oxygenxml.com/2015/07/controlled-attribute-values-for-your.html" target="_blank">Controlled Attribute Values for your DITA         Project</a></strong>, Oxygen allows you to add or replace possible values for attributes or       elements based on a simple configuration file. A more complex scenario is one in which in       order to decide which values to provide, you need more context information. Let's take this       DITA fragment:</p>       <pre class="pre codeblock language-xml"><strong class="hl-tag" style="color:#000096">&lt;metadata&gt;</strong><br />    <strong class="hl-tag" style="color:#000096">&lt;othermeta</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"name"</span> <span class="hl-attribute" style="color: #ff7935">content</span>=<span class="hl-value" style="color: #993300">"value"</span><strong class="hl-tag" style="color:#000096">/&gt;</strong><br /><strong class="hl-tag" style="color:#000096">&lt;/metadata&gt;</strong></pre>       <p class="p">What we want is to offer proposals for <dfn class="term">@content</dfn> but the possible values for         <dfn class="term">@content</dfn> depend on the value of <dfn class="term">@name</dfn>. We will see how we can       solve this dependency.</p>     <div class="section"><h2 class="title sectiontitle">The configuration file</h2>             <div class="p">The configuration file (<strong class="ph b">cc_value_config.xml</strong>) allows <a class="xref" href="http://www.oxygenxml.com/doc/versions/17.0/ug-editor/#topics/configuring-content-completion-proposals.html" target="_blank">calling an XSLT stylesheet</a> and that's just what we         will         do:<pre class="pre codeblock language-xml"><strong class="hl-tag" style="color:#000096">&lt;match</strong> <span class="hl-attribute" style="color: #ff7935">elementName</span>=<span class="hl-value" style="color: #993300">"othermeta"</span> <span class="hl-attribute" style="color: #ff7935">attributeName</span>=<span class="hl-value" style="color: #993300">"content"</span><strong class="hl-tag" style="color:#000096">&gt;</strong><br />    <strong class="hl-tag" style="color:#000096">&lt;xslt</strong> <span class="hl-attribute" style="color: #ff7935">href</span>=<span class="hl-value" style="color: #993300">"meta.xsl"</span> <span class="hl-attribute" style="color: #ff7935">useCache</span>=<span class="hl-value" style="color: #993300">"false"</span><strong class="hl-tag" style="color:#000096">/&gt;</strong><br /><strong class="hl-tag" style="color:#000096">&lt;/match&gt;</strong></pre></div>       <p class="p">As you can see, we can't express the dependency between <dfn class="term">@content</dfn> and           <dfn class="term">@name</dfn> inside the configuration file . I also want to mention that because the         values for <dfn class="term">@content</dfn> are dynamic, we want the XSLT script to execute every time         the values are requested (we shouldn't cache the results). We enforce this by setting           <dfn class="term">@useCache</dfn> to <dfn class="term">false</dfn>.</p>     </div>     <div class="section"><h2 class="title sectiontitle">The XSLT script</h2>             <div class="p">The XSLT script has access to the XML document (through the <dfn class="term">documentSystemID</dfn>        parameter) but it lacks any context information, we can't really tell for which           <dfn class="term">othermeta</dfn> element was the script invoked. To counter this limitation, we will         use Java extension functions and we will call Oxygen's Java-based API from the XSLT. Here         how it         looks:<pre class="pre codeblock language-xml"><span class="hl-directive" style="color:#8b26c9">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span><br /><strong style="color: #0066FF">&lt;xsl:stylesheet</strong> <span class="hl-attribute" style="color: #ff7935">xmlns:xsl</span>=<span class="hl-value" style="color: #993300">"http://www.w3.org/1999/XSL/Transform"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:xs</span>=<span class="hl-value" style="color: #993300">"http://www.w3.org/2001/XMLSchema"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:xd</span>=<span class="hl-value" style="color: #993300">"http://www.oxygenxml.com/ns/doc/xsl"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:tei</span>=<span class="hl-value" style="color: #993300">"http://www.oxygenxml.com/ns/doc/xsl"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:prov</span>=<span class="hl-value" style="color: #993300">"java:ro.sync.exml.workspace.api.PluginWorkspaceProvider"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:work</span>=<span class="hl-value" style="color: #993300">"java:ro.sync.exml.workspace.api.PluginWorkspace"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:editorAccess</span>=<span class="hl-value" style="color: #993300">"java:ro.sync.exml.workspace.api.editor.WSEditor"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:saxon</span>=<span class="hl-value" style="color: #993300">"http://saxon.sf.net/"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:textpage</span>=<span class="hl-value" style="color: #993300">"java:ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:authorPage</span>=<span class="hl-value" style="color: #993300">"java:ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage"</span><br />    <span class="hl-attribute" style="color: #ff7935">xmlns:ctrl</span>=<span class="hl-value" style="color: #993300">"java:ro.sync.ecss.extensions.api.AuthorDocumentController"</span><br />    <span class="hl-attribute" style="color: #ff7935">exclude-result-prefixes</span>=<span class="hl-value" style="color: #993300">"xs xd"</span><br />    <span class="hl-attribute" style="color: #ff7935">version</span>=<span class="hl-value" style="color: #993300">"2.0"</span><strong style="color: #0066FF">&gt;</strong><br />    <strong style="color: #0066FF">&lt;xsl:param</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"documentSystemID"</span> <span class="hl-attribute" style="color: #ff7935">as</span>=<span class="hl-value" style="color: #993300">"xs:string"</span><strong style="color: #0066FF">&gt;</strong><strong style="color: #0066FF">&lt;/xsl:param&gt;</strong><br />    <br />    <strong style="color: #0066FF">&lt;xsl:template</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"start"</span><strong style="color: #0066FF">&gt;</strong><br />        <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"workspace"</span> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"prov:getPluginWorkspace()"</span><strong style="color: #0066FF">/&gt;</strong><br />        <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"editorAccess"</span> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"work:getEditorAccess($workspace, xs:anyURI($documentSystemID), 0)"</span><strong style="color: #0066FF">/&gt;</strong><br />        <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"pageID"</span> <span class="hl-attribute" style="color: #ff7935">as</span>=<span class="hl-value" style="color: #993300">"xs:string"</span> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"editorAccess:getCurrentPageID($editorAccess)"</span><strong style="color: #0066FF">/&gt;</strong><br />        <br />        <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"name"</span> <span class="hl-attribute" style="color: #ff7935">as</span>=<span class="hl-value" style="color: #993300">"xs:string"</span><strong style="color: #0066FF">&gt;</strong><br />            <strong style="color: #0066FF">&lt;xsl:choose&gt;</strong><br />                <strong style="color: #0066FF">&lt;xsl:when</strong> <span class="hl-attribute" style="color: #ff7935">test</span>=<span class="hl-value" style="color: #993300">"$pageID='Text'"</span><strong style="color: #0066FF">&gt;</strong><br />                    <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"textpage"</span> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"editorAccess:getCurrentPage($editorAccess)"</span><strong style="color: #0066FF">/&gt;</strong><br />                    <em class="hl-comment" style="color:#006400">&lt;!-- In the text page, the context is the @content attribute --&gt;</em><br />                    <strong style="color: #0066FF">&lt;xsl:value-of</strong> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"textpage:evaluateXPath($textpage, 'xs:string(./parent::node()/@name)')"</span><strong style="color: #0066FF">/&gt;</strong><br />                <strong style="color: #0066FF">&lt;/xsl:when&gt;</strong><br />                <strong style="color: #0066FF">&lt;xsl:when</strong> <span class="hl-attribute" style="color: #ff7935">test</span>=<span class="hl-value" style="color: #993300">"$pageID='Author'"</span><strong style="color: #0066FF">&gt;</strong><br />                    <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"authorPage"</span> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"editorAccess:getCurrentPage($editorAccess)"</span><strong style="color: #0066FF">/&gt;</strong><br />                    <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"caretOffset"</span> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"authorPage:getCaretOffset($authorPage)"</span><strong style="color: #0066FF">/&gt;</strong><br />                    <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"ctrl"</span> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"authorPage:getDocumentController($authorPage)"</span><strong style="color: #0066FF">/&gt;</strong><br />                    <strong style="color: #0066FF">&lt;xsl:variable</strong> <span class="hl-attribute" style="color: #ff7935">name</span>=<span class="hl-value" style="color: #993300">"contextNode"</span> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"ctrl:getNodeAtOffset($ctrl, $caretOffset)"</span><strong style="color: #0066FF">/&gt;</strong><br />                    <em class="hl-comment" style="color:#006400">&lt;!-- In the author page, the context is the "othermeta" element --&gt;</em><br />                    <strong style="color: #0066FF">&lt;xsl:value-of</strong> <span class="hl-attribute" style="color: #ff7935">select</span>=<span class="hl-value" style="color: #993300">"ctrl:evaluateXPath($ctrl, 'xs:string(@name)', $contextNode, false(), false(), false(), false())[1]"</span><strong style="color: #0066FF">/&gt;</strong><br />                <strong style="color: #0066FF">&lt;/xsl:when&gt;</strong><br />            <strong style="color: #0066FF">&lt;/xsl:choose&gt;</strong><br />        <strong style="color: #0066FF">&lt;/xsl:variable&gt;</strong><br />        <br />        <strong class="hl-tag" style="color:#000096">&lt;items&gt;</strong>        <br />            <strong style="color: #0066FF">&lt;xsl:choose&gt;</strong><br />                <strong style="color: #0066FF">&lt;xsl:when</strong> <span class="hl-attribute" style="color: #ff7935">test</span>=<span class="hl-value" style="color: #993300">"$name = 'temperatureScale'"</span><strong style="color: #0066FF">&gt;</strong><br />                    <strong class="hl-tag" style="color:#000096">&lt;item</strong> <span class="hl-attribute" style="color: #ff7935">value</span>=<span class="hl-value" style="color: #993300">"Celsius"</span> <span class="hl-attribute" style="color: #ff7935">annotation</span>=<span class="hl-value" style="color: #993300">"(symbol C)"</span><strong class="hl-tag" style="color:#000096">/&gt;</strong><br />                    <strong class="hl-tag" style="color:#000096">&lt;item</strong> <span class="hl-attribute" style="color: #ff7935">value</span>=<span class="hl-value" style="color: #993300">"Fahrenheit"</span> <span class="hl-attribute" style="color: #ff7935">annotation</span>=<span class="hl-value" style="color: #993300">"(symbol F)"</span><strong class="hl-tag" style="color:#000096">/&gt;</strong><br />                <strong style="color: #0066FF">&lt;/xsl:when&gt;</strong><br />                <strong style="color: #0066FF">&lt;xsl:when</strong> <span class="hl-attribute" style="color: #ff7935">test</span>=<span class="hl-value" style="color: #993300">"$name = 'measurement'"</span><strong style="color: #0066FF">&gt;</strong><br />                    <strong class="hl-tag" style="color:#000096">&lt;item</strong> <span class="hl-attribute" style="color: #ff7935">value</span>=<span class="hl-value" style="color: #993300">"Metric"</span> <span class="hl-attribute" style="color: #ff7935">annotation</span>=<span class="hl-value" style="color: #993300">"Metric system"</span><strong class="hl-tag" style="color:#000096">/&gt;</strong><br />                    <strong class="hl-tag" style="color:#000096">&lt;item</strong> <span class="hl-attribute" style="color: #ff7935">value</span>=<span class="hl-value" style="color: #993300">"Imperial"</span> <span class="hl-attribute" style="color: #ff7935">annotation</span>=<span class="hl-value" style="color: #993300">"Also known as British Imperial"</span><strong class="hl-tag" style="color:#000096">/&gt;</strong><br />                <strong style="color: #0066FF">&lt;/xsl:when&gt;</strong><br />            <strong style="color: #0066FF">&lt;/xsl:choose&gt;</strong><br />        <strong class="hl-tag" style="color:#000096">&lt;/items&gt;</strong><br />    <strong style="color: #0066FF">&lt;/xsl:template&gt;</strong>    <br /><strong style="color: #0066FF">&lt;/xsl:stylesheet&gt;</strong></pre></div>       <p class="p">It is also worth mentioning that in the next Oxygen version (17.1) we will provide a more         elegant solution to this situation. The XSLT script will receive a new parameter, an XPath         expression that will identify the element for which content completion was invoked. But         maybe we will talk about that in a future post...</p>     </div>   </div><img src="http://feeds.feedburner.com/~r/AboutOxygenXmlEditor/~4/NE2VjDi24KA?utm_source=feedburner&utm_medium=email" height="1" width="1" alt=""/></div>
</td>
</tr>
</table>
<table style="border-top:1px solid #999;padding-top:4px;margin-top:1.5em;width:100%" id="footer">
<tr>
<td style="text-align:left;font-family:Helvetica,Arial,Sans-Serif;font-size:11px;margin:0 6px 1.2em 0;color:#333;">You are subscribed to email updates from <a href="http://blog.oxygenxml.com/">About oXygen XML Editor</a>
<br />To stop receiving these emails, you may <a href="https://feedburner.google.com/fb/a/mailunsubscribe?k=y_tRXtumvTurKTedh51JnlYsGXw">unsubscribe now</a>.</td>
<td style="font-family:Helvetica,Arial,Sans-Serif;font-size:11px;margin:0 6px 1.2em 0;color:#333;text-align:right;vertical-align:top">Email delivery powered by Google</td>
</tr>
<tr>
<td colspan="2" style="text-align:left;font-family:Helvetica,Arial,Sans-Serif;font-size:11px;margin:0 6px 1.2em 0;color:#333;">Google Inc., 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States</td>
</tr>
</table>
</div>
</body>
</html>