1

Orbeon Forms では、次のようなインスタンスにバインドされたときに (XBL を使用して) コンポーネントを作成する必要があります。

<OCinstructionitem>
  <OCp>paragraph 1</OCp>
  <OCp>paragraph 2 <OCem>with italics part</OCem> rest of paragraph 2 </OCp>
</OCinstructionitem>

次のような編集可能な div を作成します。

<div contentEditable="true">
  <p>paragraph 1</p>
  <p>paragraph 2 <i>with italics part</i> rest of paragraph 2 </p>
</div>

私の考えでは、XSLT を使用してこれを行う必要があります。変換される XML が xforms ドキュメント内にある場合、これが機能します。

<oc:instructionitem>
   <OCinstructionitem>
      <!-- here the xml of above -->
      ...
   </OCinstructionitem>
</oc:instructionitem> 

しかし、次のようにバインドされたノードで XSLT を動作させたいと考えています。

<oc:instructionitem ref="OCinstructionitem"/>

ただし、バインドされたノードに XSLT からアクセスできません。

私の質問: それは不可能ですか? または、XBL を変更する必要がありますか?

私のXBLコード:

<xbl:binding id="oc-instructionitem" element="oc|instructionitem">
    <xbl:template xxbl:transform="oxf:xslt">
        <xsl:transform version="2.0">
              <xsl:template match="@*|node()" priority="-100">
                   <xsl:apply-templates select="@*|node()"/>
              </xsl:template>
              <xsl:template match="text()" priority="-100" mode="in-paragraph">
                  <xsl:copy>
                     <xsl:value-of select="."/>
                  </xsl:copy>
              </xsl:template>
              <xsl:template match="OCem" mode="in-paragraph">
                  <x:i><xsl:value-of select="."/></x:i>
              </xsl:template>
              <xsl:template match="OCp">
                  <x:div>
                      <xsl:apply-templates mode="in-paragraph"/>
                  </x:div>
              </xsl:template>
              <xsl:template match="/*">
                <x:div contentEditable="true">
                    <xsl:apply-templates/>
                </x:div>
            </xsl:template>
    </xsl:transform>
    </xbl:template>
</xbl:binding>

</xbl:xbl>

どんな助けでも大歓迎です、

編集: tohuwawohu の有益なコメントの後 (以下) インスタンス データにバインドされる変数を定義する必要があるようです。このような:

<xsl:template match="oc:instructionitem">
   <xforms:group xbl:attr="model context ref bind" xxbl:scope="outer">
      <xxforms:variable name="binding" as="node()?" xxbl:scope="inner" >
         <xxforms:sequence select="." xxbl:scope="outer"/>
      </xxforms:variable>
      <xforms:group xxbl:scope="inner">
         <!-- Variable pointing to external single-node binding -->
         <xforms:group ref="$binding">
              <xsl:call-template name="main"/>
         </xforms:group>
      </xforms:group>
   </xforms:group>
</xsl:template>
<xsl:template name="main">
    <x:div contentEditable="true">
       <xforms:repeat nodeset="*">
           <xsl:call-template name="paragraph"/>
       </xforms:repeat>
    </x:div>
</xsl:template>

ただし、XSLT 要素は依然としてデータを操作できません。データを操作できる XFORMS 要素のみを生成できます。これは、 <xsl:template match="OCp"> のようなものが選択されないことを意味します。これが、上記のコードが名前付きテンプレートを使用する理由です。つまり、バインドされたデータを xslt コードで使用できるようにすることはできますか?

マルティン

4

1 に答える 1

0

私はそれをテストしませんでしたが、カプセル化を破ることで可能になるはずです。これがないと、3 番目のコード スニペットのように、XBL はバインドされたノードのコンテンツにしかアクセスできなくなります。XBL を XForms インスタンス データにアクセスさせたい場合は、バインドされたノードの単一ノード バインディングを指す XBL 内の変数を宣言する必要があります。

Wiki の例のコード スニペットを次に示します。

<xforms:group xbl:attr="model context ref bind" xxbl:scope="outer">
    <xforms:group xxbl:scope="inner">
        <!-- Variable pointing to external single-node binding -->
        <xxforms:variable name="binding" as="node()?">
            <xxforms:sequence select="." xxbl:scope="outer"/>
        </xxforms:variable>
        ...
    </xforms:group>
</xforms:group>

このように単一ノード バインディングを定義すると、その変数を参照して xslt 変換に使用できるようになります。ルート ノードに一致する XSLT テンプレート要素を置き換えて、変数の内容を指すだけです$binding

<xsl:transform version="2.0">
    <xsl:template match="@*|node()" priority="-100">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:template>
    <xsl:template match="text()" priority="-100" mode="in-paragraph">
        <xsl:copy>
            <xsl:value-of select="."/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="OCem" mode="in-paragraph">
        <x:i><xsl:value-of select="."/></x:i>
    </xsl:template>
    <xsl:template match="OCp">
        <x:div>
            <xsl:apply-templates mode="in-paragraph"/>
        </x:div>
    </xsl:template>
    <xsl:template match="oc:instructionitem">
        <xforms:group ref="$binding">
          <x:div contentEditable="true">
              <xsl:apply-templates/>
          </x:div>
        </xforms:group>
    </xsl:template>

これがうまくいくことを願っています。バインドされたノード (あなたの例では: ) が空でない場合、これには準備が必要になる可能性があるため、xslt はそのコンテンツと変数oc:instructionitemのコンテンツの両方を処理する可能性があります。$binding

于 2011-08-02T08:44:43.177 に答える