1
votes

Is there a way to wrap marked text in element using xforms? For example:

Put tag around this word --> Put tag around this <tag>word</tag>

I'm new to xforms, currently using Xsltxforms on exist-db server and I'm trying to figure out if I'm missing something or there's no way to make such a thing in textarea box for example. Thank you in advance!

2

2 Answers

2
votes

There is no mechanism in XForms Recommendation for such a processing.

But this has been added as an extension in XSLTForms: an extra action named "xf:wrap" allows to indicate with control is to be considered and what is to be added before and after the selection.

<?xml-stylesheet href="xsl/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
    <title>Wrap Selection</title>
    <xf:model>
        <xf:instance>
            <data xmlns="">Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo.</data>
        </xf:instance>
    </xf:model>
</head>
<body>
    <xf:trigger>
        <xf:label>&lt;a&gt;</xf:label>
        <xf:wrap ev:event="DOMActivate" control="t" pre="&lt;a&gt;" post="&lt;/a&gt;"/>
    </xf:trigger>
    <xf:trigger>
        <xf:label>&lt;b&gt;</xf:label>
        <xf:wrap ev:event="DOMActivate" control="t" pre="&lt;b&gt;" post="&lt;/b&gt;"/>
    </xf:trigger>
    <xf:trigger>
        <xf:label>&lt;c&gt;</xf:label>
        <xf:wrap ev:event="DOMActivate" control="t" pre="&lt;c&gt;" post="&lt;/c&gt;"/>
    </xf:trigger>
    <br/>
    <xf:textarea id="t" ref="." incremental="true"/>
    <br/>
    <xf:output value=".">
        <xf:label>Value: </xf:label>
    </xf:output>
</body>
</html>

There is yet another possibility with the xf:setselection action:

<?xml-stylesheet href="xsl/xsltforms.xsl" type="text/xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
    <title>Set Selection</title>
    <xf:model>
        <xf:instance>
            <data xmlns="">Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium...</data>
        </xf:instance>
    </xf:model>
</head>
<body>
    <xf:trigger>
        <xf:label>&lt;span&gt;</xf:label>
        <xf:setselection ev:event="DOMActivate" control="t" value="concat('&lt;span start=&quot;', control-property('t', 'selectionStart'), '&quot; end=&quot;', control-property('t', 'selectionEnd'), '&quot;&gt;', selection('t'), '&lt;/span&gt;')"/>
    </xf:trigger>
    <br/>
    <xf:textarea id="t" ref="." incremental="true"/>
    <br/>
    <xf:output value=".">
        <xf:label>Value: </xf:label>
    </xf:output>
</body>
</html>

Live demo: http://www.agencexml.com/direct/wrap/setselection.xml

What do you think?

2
votes

Amended answer: Some possible solutions are to integrate a library such as Rangy (https://github.com/timdown/rangy) into XSLTForms, or even a rich-text editor such as TinyMCE (which XSLTForms does in this example: http://www.agencexml.com/xsltforms/tinymce.xml). Another option would be to look at Teian(https://sourceforge.net/projects/teian/) which is designed for TEI, but could be a step in the right direction.