Note that there are some explanatory texts on larger screens.

plurals
  1. POorbeon: applying xslt transform in xbl on bound document
    primarykey
    data
    text
    <p>In Orbeon Forms I need to create a component (using XBL) that when bound to an instance like</p> <pre><code>&lt;OCinstructionitem&gt; &lt;OCp&gt;paragraph 1&lt;/OCp&gt; &lt;OCp&gt;paragraph 2 &lt;OCem&gt;with italics part&lt;/OCem&gt; rest of paragraph 2 &lt;/OCp&gt; &lt;/OCinstructionitem&gt; </code></pre> <p>creates an editable div like this:</p> <pre><code>&lt;div contentEditable="true"&gt; &lt;p&gt;paragraph 1&lt;/p&gt; &lt;p&gt;paragraph 2 &lt;i&gt;with italics part&lt;/i&gt; rest of paragraph 2 &lt;/p&gt; &lt;/div&gt; </code></pre> <p>My thought was that I need to do this using XSLT. I get this working when the to-be-transformed XML is inside the xforms document:</p> <pre><code>&lt;oc:instructionitem&gt; &lt;OCinstructionitem&gt; &lt;!-- here the xml of above --&gt; ... &lt;/OCinstructionitem&gt; &lt;/oc:instructionitem&gt; </code></pre> <p>but I want to let the XSLT operate on the bound node as in:</p> <pre><code>&lt;oc:instructionitem ref="OCinstructionitem"/&gt; </code></pre> <p>However, I canot access the bound node from the XSLT.</p> <p>My question: is that just not possible? Or do I have to modify my XBL? </p> <p>My XBL code: </p> <pre><code>&lt;xbl:binding id="oc-instructionitem" element="oc|instructionitem"&gt; &lt;xbl:template xxbl:transform="oxf:xslt"&gt; &lt;xsl:transform version="2.0"&gt; &lt;xsl:template match="@*|node()" priority="-100"&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="text()" priority="-100" mode="in-paragraph"&gt; &lt;xsl:copy&gt; &lt;xsl:value-of select="."/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="OCem" mode="in-paragraph"&gt; &lt;x:i&gt;&lt;xsl:value-of select="."/&gt;&lt;/x:i&gt; &lt;/xsl:template&gt; &lt;xsl:template match="OCp"&gt; &lt;x:div&gt; &lt;xsl:apply-templates mode="in-paragraph"/&gt; &lt;/x:div&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/*"&gt; &lt;x:div contentEditable="true"&gt; &lt;xsl:apply-templates/&gt; &lt;/x:div&gt; &lt;/xsl:template&gt; &lt;/xsl:transform&gt; &lt;/xbl:template&gt; &lt;/xbl:binding&gt; &lt;/xbl:xbl&gt; </code></pre> <p>Any help would be greatly appreciated,</p> <p>edit: after helpfull comment of tohuwawohu (below) It seems that you need to define a variable which is bound to the instance data. Like this:</p> <pre><code>&lt;xsl:template match="oc:instructionitem"&gt; &lt;xforms:group xbl:attr="model context ref bind" xxbl:scope="outer"&gt; &lt;xxforms:variable name="binding" as="node()?" xxbl:scope="inner" &gt; &lt;xxforms:sequence select="." xxbl:scope="outer"/&gt; &lt;/xxforms:variable&gt; &lt;xforms:group xxbl:scope="inner"&gt; &lt;!-- Variable pointing to external single-node binding --&gt; &lt;xforms:group ref="$binding"&gt; &lt;xsl:call-template name="main"/&gt; &lt;/xforms:group&gt; &lt;/xforms:group&gt; &lt;/xforms:group&gt; &lt;/xsl:template&gt; &lt;xsl:template name="main"&gt; &lt;x:div contentEditable="true"&gt; &lt;xforms:repeat nodeset="*"&gt; &lt;xsl:call-template name="paragraph"/&gt; &lt;/xforms:repeat&gt; &lt;/x:div&gt; &lt;/xsl:template&gt; </code></pre> <p>However, the XSLT elements still cannot act on the data. It can only generate XFORMS elements, which can act on the data. This means that something like &lt;xsl:template match="OCp"&gt; will never be selected. This is why the above code uses named templates. So the question still stands: can the bound data be made available to the xslt code?</p> <p>Martijn</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload