0

誰かがこれで私を助けてくれることを願っています。私はそれを理解しようとして頭を悩ませてきました-今日と昨日の試みの大部分についてstackoverflowを読んでいますが、まだそこにあるわけではありません.

これがcmsから生成された私のxmlです。

<Navigation Type="Children" Name="LeftNavigation" label="Left Navigation">
      <Page ID="x13" URL="x13.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="Cars" />
        <Page ID="x12" URL="x12.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-1">
        <Page ID="x27" URL="x27.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-2" />
        <Page ID="x28" URL="x28.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-3" />
        <Page ID="x31" URL="x31.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-4" />
      </Page>
      -
      <Page ID="x14" URL="x14.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="Books">
        <Page ID="x32" URL="x32.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-2" />
        <Page ID="x33" URL="x33.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-3" />
        <Page ID="x34" URL="x34.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-4" />
        <Page ID="x35" URL="x35.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-5" />
        <Page ID="x36" URL="x36.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-6" />
        <Page ID="x37" URL="x37.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-7" />
        <Page ID="x38" URL="x38.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-8" />
        <Page ID="x39" URL="x39.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-9" />
        <Page ID="x40" URL="x40.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-10" />
        <Page ID="x41" URL="x41.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="subsection-11" />
      </Page>
      <Page ID="x15" URL="x15.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="Clothes" />
      -
      <Page ID="x47" URL="x47.xml" Schema="ContentPage" Locale="en-us" CategoryIds="" Name="Toys">
        <Page ID="x49" URL="x49.xml" Schema="ContentPage" Locale="en-us"  CategoryIds="" Name="subsection-1" />
        <Page ID="x48" URL="x48.xml" Schema="ContentPage" Locale="en-us"  CategoryIds="" Name="subsection-2" />
      </Page>
    </Navigation>

私がこれでやろうとしているのは、その親の子または兄弟のみをリストする左側のナビゲーションを作成することです。

だから私はこのようなことを試してきました:

<xsl:variable name="currentPage">
    <xsl:value-of select="//ContentPage/@ID"/>
  </xsl:variable>

最初に、自分がどこにいるかを調べて属性 ID を取得する変数を作成しました。

<xsl:template name="navigation">
    <ul id="oc-left-nav">
      <xsl:apply-templates select="//@ID='$currentPage' | parent::()" />
    </ul>
  </xsl:template>

したがって、この部分は私の試みです: 私の変数と等しい ID を持つページを選択するか、兄弟である場合は、その親の下にすべての兄弟をリストします。しかし、ご覧のとおり、私はそれを書く方法がわかりません。

  <xsl:template match="//@ID[.='$currentPage'] | parent::()">
    <xsl:for-each select="Page">
      <li class="oc-navlink">
        <a>
          <xsl:attribute name="href">
            <xsl:value-of select="@URL"/>
          </xsl:attribute>
          <xsl:value-of select="@Name"/>
        </a>
      </li>
    </xsl:for-each>
  </xsl:template>

結局のところ、あなたが子孫である親ページに関連するすべての子の動的リストが必要です。さて、期待です。私はそれを差し込んでいきます。

4

1 に答える 1

0

あなたが何をしようとしているのか理解できませんが、確かにいくつかの観察を行うことができます:

あなたは、「だから、この部分は私の試みです:ページを選択してください...」

@ID ノードを返すテンプレート マッチが続きます ...

xsl:template match="//@ID ..

「@ID」属性の子「Page」要素に対して for-each を実行しても、何も返されません。「@ID」属性には子がありません。

次に、変数 currentPage の値を //ContentPage/@ID に設定します。サンプル XML には ContentPage という要素さえ表示されません。ここに関連するすべてのものを表示しない限り、この変数は空になります。

出力に何を求めているかはわかっていると思いますが、推測する必要がないように、期待どおりの結果を投稿できるかもしれません。

于 2013-06-19T04:29:43.870 に答える