2016-10-03 8 views
0

Xpath 1.0とXalanJ 2.7.1でxslt 1.0を使用します。 テンプレートのプロファイリングを行い、通話時間を短縮しようとします。だから、うちの最大のホットスポットがある:XSLT 1.0を使用したテンプレートのxslt処理中の最適化?

<xsl:template name="tplAttribute"> 
    <xsl:param name="sourceObject" /> 
    <xsl:param name="sourceName" /> 
    <xsl:param name="targetName" /> 

    <xsl:variable name="sourceAttribute" select="$sourceObject/attribute[@name = $sourceName]" /> 
    <xsl:if test="$sourceAttribute"> 
     <dcx:attribute name="{$targetName}"> 
      <xsl:value-of select="$sourceAttribute" /> 
     </attribute> 
    </xsl:if> 
</xsl:template> 

871本のヒット時の平均時間は103と、可変59msのためです。

変換の時間を短縮するために、より良い解決策はありますか?

編集:ときプロセス 入力構造テンプレートを呼び出し、 'sourceObject':

object 
    tplAttribute 
    tplAttribute 
    tplAttributeDefault 
    tplAttribute 
    tplAttributeSomeDifferentLogic 
    tplAttribute 
    tplAttributeOther 

enter image description here

+0

通常、いくつの「属性」要素が$ sourceObjectの子として検出されますか? –

+0

20から100までですが、$ sourceObjectがありますので、その中に特定の属性を見つけなければなりません。しかし、それから別のものを探す必要があります。状況によっては、tplAttributeOtherなどのロジックが異なるため、変数の作成によって処理が遅くなったり、sourceAttributeではなく2つの選択肢がある場合は、プロセッサの最適化に基づいてより高速になります。 – Xelian

+0

私はXalanの内部を知らない。 Saxon-EEは、おそらくこれを評価するための指標を作成します。試して結果をお知らせください。 –

答えて

0

キー<xsl:key name="att-by-name" match="attribute" use="@name"/>を定義して、

<xsl:for-each select="$sourceObject"> 
    <xsl:if test="key('att-by-name', $sourceName)"> 
      <dcx:attribute name="{$targetName}"> 
       <xsl:value-of select="key('att-by-name', $sourceName)" /> 
      </attribute> 
    </xsl:if> 
</xsl:for-each> 

代わりの

を使用します
<xsl:variable name="sourceAttribute" select="$sourceObject/attribute[@name = $sourceName]" /> 
    <xsl:if test="$sourceAttribute"> 
     <dcx:attribute name="{$targetName}"> 
      <xsl:value-of select="$sourceAttribute" /> 
     </attribute> 
    </xsl:if> 

あなたはattribute要素のname属性は、あなたが完全に文書で探しているattribute要素(複数可)を識別する場合に示されているようなアプローチをベースキーが動作します、私たちにsourceObjectと、文書の正確な構造を表示する必要がある場合があります。サブツリーを調べているだけの場合は、キー値にidを含める必要があります。

関連する問題