Saxon XSLTパーサがトンネルパラメータの受け渡しを最適化するかどうか不思議です。同じ値を使用した場合は再作成されますか?それとも、現在のコピーを使用していますか?Saxon XSLTプロセッサは、トンネルパラメータを現在の値に設定するために最適化しますか?
例を示す必要はありませんが、私は以下の特定の使用例を説明しようとしました。
例の入力XML:
<formDefinition sysid="1">
<subform sysid="2">
<subform layoutGrid="8" sysid="3">
<field weight="2" sysid="4">
<bind match="none" />
<type><date /></type>
</field>
</subform>
</subform>
</formDefinition>
は、いくつかのコンテキストを提供するために - サブフォーム要素は、HTML DIV要素と同様であり、フィールド要素は、HTMLのINPUT要素に類似しています。 layoutGrid属性は、サブフォームによって設定またはオーバーライドされ、フィールドなどの子孫によって使用されます。
私の実際のスタイルシートと 'formDefinition'は、パーティション化が困難な関連性のある設定が多い多くのトンネルパラメータを使用しているため、パラメータを既存の値にリセットすることは避けがたいです。
ここでは、トンネルパラメータの1つのみを設定する方法を説明するための一般的なフローを以下に試しました。
例スタイルシート -
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[@sysid]">
<xsl:apply-templates select="." mode="render" />
</xsl:template>
<xsl:template match="/formDefinition" mode="render">
<xsl:copy>
<xsl:next-match />
</xsl:copy>
</xsl:template>
<xsl:template match="subform" mode="render">
<xsl:param name="pLayoutGrid" as="xs:decimal" tunnel="yes" />
<xsl:copy>
<xsl:attribute name="effLayoutGrid" select="$pLayoutGrid" />
<xsl:next-match />
</xsl:copy>
</xsl:template>
<xsl:template match="field" mode="render">
<xsl:param name="pLayoutGrid" as="xs:decimal" tunnel="yes" />
<xsl:copy>
<xsl:attribute name="effLayoutGrid" select="$pLayoutGrid" />
<xsl:next-match />
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="render">
<xsl:apply-templates select="*[not(@sysid)]" />
<xsl:call-template name="step" />
</xsl:template>
<xsl:template name="step">
<xsl:apply-templates select="*[@sysid]">
<xsl:with-param name="pLayoutGrid" as="xs:decimal" tunnel="yes">
<xsl:apply-templates select="." mode="layoutGrid" />
</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="/formDefinition" mode="layoutGrid">
<xsl:sequence select="xs:decimal(12)" />
</xsl:template>
<xsl:template match="subform" mode="layoutGrid">
<xsl:param name="pLayoutGrid" as="xs:decimal" tunnel="yes" />
<!-- potentially resetting the same value here -->
<xsl:sequence select="(@layoutGrid, $pLayoutGrid)[1]" />
</xsl:template>
<xsl:template match="field" mode="layoutGrid">
<xsl:param name="pLayoutGrid" as="xs:decimal" tunnel="yes" />
<!-- setting value to current value -->
<xsl:sequence select="$pLayoutGrid" />
</xsl:template>
</xsl:stylesheet>
出力:
<formDefinition>
<subform effLayoutGrid="12">
<subform effLayoutGrid="12">
<field effLayoutGrid="8">
<bind match="none" />
<type>
<date />
</type>
</field>
</subform>
</subform>
</formDefinition>
例の文脈での私の質問は、 - pLayoutGridトンネルパラメータは、実際に新しい「オブジェクト」を作成リセットしない、またはそれを再利用しません値が現在の値に戻されたときの現在の値?
私のフルコードでは、xml要素/ツリーであるトンネルパラメータもあります。私は、基本的な型とxml要素の間に違いがあるのだろうかと思うので、これについて言及します。
Dr. Kayさん、ありがとうございます。あなたの説明に基づいて、私のコードでトンネルパラメータを再宣言するコストは低くなるはずです。 – dave
それを測定し、結果を共有してください。 –