質問

私はUmbraco XSL StyleSheetに取り組んでいますが、かなり立ち往生しています。

基本的に、私はテストするパラメーターがあり、それが存在する場合に値を使用します。そうしないと、デフォルトのパラメーターを使用します $currentPage.

パラメーターは次のとおりです

<xsl:param name="source" select="/macro/sourceId" />
<xsl:param name="currentPage" />

これが変数です

<xsl:variable name="current">
    <xsl:choose>
        <xsl:when test="$source &gt; 0">
            <xsl:copy-of select="umbraco.library:GetXmlNodeById($source)" />
        </xsl:when>
        <xsl:otherwise>
            <xsl:copy-of select="$currentPage" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:variable>

そして、ここで私がそれを使用しています

<xsl:for-each select="msxml:node-set($source)/ancestor-or-self::* [@isDoc and @level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
... code here ...
</xsl:for-each>


手短に

これは機能します

<xsl:variable name="source" select="$currentPage" />

これはそうではありません

<xsl:variable name="source">
  <xsl:copy-of select="$currentPage" /> <!-- Have tried using <xsl:value-of /> as well -->
</xsl:variable>

では、使用せずに変数をどのようにコピーしますか select="" 属性。

アップデート: 別のアプローチを使用してみました(以下を参照)が、 範囲外変数 例外。

<xsl:choose>
    <xsl:when test="$source &gt; 0">
        <xsl:variable name="current" select="umbraco.library:GetXmlNodeById($source)" />
    </xsl:when>
    <xsl:otherwise>
        <xsl:variable name="current" select="$currentPage" />
    </xsl:otherwise>
</xsl:choose>
役に立ちましたか?

解決

一般に、この式は、特定の条件が true() また false():

$ns1[$cond] | $ns2[not($cond)]

あなたの場合、これは翻訳されます:

    umbraco.library:GetXmlNodeById($source) 
|
    $currentPage[not(umbraco.library:GetXmlNodeById($source))]

完全 <xsl:variable> 定義はです:

<xsl:variable name="vCurrent" select=
"        umbraco.library:GetXmlNodeById($source) 
    |
        $currentPage[not(umbraco.library:GetXmlNodeById($source))]
"/>

これは、よりコンパクトな方法で書くことができます:

<xsl:variable name="vRealSource" select="umbraco.library:GetXmlNodeById($source)"/>

<xsl:variable name="vCurrent" select=
    "$vRealSource| $currentPage[not($vRealSource)]"/>

他のヒント

@SelectなしでXSLT 1.0で変数を宣言すると、一部のコンテンツテンプレートを使用すると、変数タイプは結果ツリーフラグメントになります。変数は、このツリーフラグメントのルートノードを保持します。

だから、これで:

<xsl:variable name="source"> 
  <xsl:copy-of select="$currentPage" />
</xsl:variable> 

あなたは宣言しています $source を含むRTFのルートとして コピー ノード(自己と子孫)の $currentPage ノードセット。

使用できません / RTFのステップ演算子。それがあなたがソシングしている理由です node-set 拡張機能。

しかし, 、 あなたが言う時:

node-set($source)/ancestor-or-self::*

ルートノードには祖先がないため、これは空のノードセットに評価されます。

編集: :2つのノードセットがあり、条件に応じて2つのノードセットのいずれかのコンテンツを含む変数を宣言する場合は、以下を使用できます。

<xsl:variable name="current" 
              select="umbraco.library:GetXmlNodeById($source)[$source > 0]
                      |$currentPage[0 >= $source]" /> 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top