Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 是否将模板应用于相邻图元?_.net_Xslt_Xslt 1.0 - Fatal编程技术网

.net 是否将模板应用于相邻图元?

.net 是否将模板应用于相邻图元?,.net,xslt,xslt-1.0,.net,Xslt,Xslt 1.0,给定如下输入: <p>Some information about the proceeding source listing:</p> <code language="CSharp"><![CDATA[ ... ]]></code> <code language="AnotherLanguage"><![CDATA[ ... ]]></code> <p>This is a differ

给定如下输入:

<p>Some information about the proceeding source listing:</p>
<code language="CSharp"><![CDATA[ ... ]]></code>
<code language="AnotherLanguage"><![CDATA[ ... ]]></code>

<p>This is a different example which perhaps applies to just one language:</p>
<code language="CSharp"><![CDATA[ ... ]]></code>

<p>Another example:</p>
<code language="CSharp"><![CDATA[ ... ]]></code>
<code language="AnotherLanguage"><![CDATA[ ... ]]></code>
<code language="YetAnotherLanguage"><![CDATA[ ... ]]></code>
... 这是一个可能仅适用于一种语言的不同示例:

  • CSharp
... 另一个例子:

  • CSharp
  • 另一种语言
  • YetAnotherLanguage
... ... ... 这就是我目前所拥有的无法正常工作的内容,因为所有源代码在所有其他内容(如本例中的段落)之后都被分组到一个选择器中



在XSLT 1.0中,您可以通过让模板一次跳到元素的下一个邻居来实现这一点,如下所示:


  • 在样例输入上运行时,将生成:

    
    有关正在进行的源代码列表的一些信息:

    • CSharp
    • 另一种语言
    ... ... 这是一个可能仅适用于一种语言的不同示例:

    • CSharp
    ... 另一个例子:

    • CSharp
    • 另一种语言
    • YetAnotherLanguage
    ... ... ...
    <p>Some information about the proceeding source listing:</p>
    <div class="source-selector">
        <ul class="tabs">
            <li class="tab" data-language="CSharp">CSharp</li>
            <li class="tab" data-language="AnotherLanguage">AnotherLanguage</li>
        </ul>
        <div data-language="CSharp">
            <pre>...</pre>
        </div>
        <div data-language="AnotherLanguage">
            <pre>...</pre>
        </div>
    </div>
    
    <p>This is a different example which perhaps applies to just one language:</p>
    <div class="source-selector">
        <ul class="tabs">
            <li class="tab" data-language="CSharp">CSharp</li>
        </ul>
        <div data-language="CSharp">
            <pre>...</pre>
        </div>
    </div>
    
    <p>Another example:</p>
    <div class="source-selector">
        <ul class="tabs">
            <li class="tab" data-language="CSharp">CSharp</li>
            <li class="tab" data-language="AnotherLanguage">AnotherLanguage</li>
            <li class="tab" data-language="YetAnotherLanguage">YetAnotherLanguage</li>
        </ul>
        <div data-language="CSharp">
            <pre>...</pre>
        </div>
        <div data-language="AnotherLanguage">
            <pre>...</pre>
        </div>
        <div data-language="YetAnotherLanguage">
            <pre>...</pre>
        </div>
    </div>
    
    <!-- Display paragraphs first -->
    <xsl:apply-templates select="*[not(name() = 'code')]"/>
    
    <!-- Display consecutive source code within selector -->
    <div class="source-selector">
        <ul class="tabs">
        <xsl:for-each select="code">
            <li class="tab" data-language="{@language}"><include item="{@language}Label"/></li>
        </xsl:for-each>
        </ul>
    <xsl:for-each select="code">
        <div data-language="{@language}">
            <pre><xsl:copy-of select="node()"/></pre>
        </div>
    </xsl:for-each>
    </div>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="/*">
        <div>
          <xsl:apply-templates select="*[not(self::code)]" />
        </div>
      </xsl:template>
    
      <xsl:template match="/*/*[not(self::code)]">
        <xsl:copy-of select="."/>
        <!-- Select the next neighbor element, but only if it is a <code> -->
        <xsl:variable name="firstCode" select="following-sibling::*[1][self::code]" />
        <div class="source-selector">
          <!-- Skip the part with the <ul> if there are no <code> neighbors-->
          <xsl:if test="$firstCode">
            <ul>
              <xsl:apply-templates select="$firstCode" mode="list" />
            </ul>
            <xsl:apply-templates select="$firstCode" mode="samples" />
          </xsl:if>
        </div>
      </xsl:template>
    
      <xsl:template match="code" mode="list">
        <li class="tab" data-language="{@language}">
          <xsl:value-of select="@language"/>
        </li>
        <!-- Apply this template to the next neighbor, if it is a <code> -->
        <xsl:apply-templates select="following-sibling::*[1][self::code]" mode="list" />
      </xsl:template>
    
      <xsl:template match="code" mode="samples">
        <div data-language="{@language}">
          <pre>
            <xsl:value-of select="string(.)"/>
          </pre>
        </div>
        <!-- Apply this template to the next neighbor, if it is a <code> -->
        <xsl:apply-templates 
                           select="following-sibling::*[1][self::code]" mode="samples" />
      </xsl:template>
    
    </xsl:stylesheet>
    
    <div>
      <p>Some information about the proceeding source listing:</p>
      <div class="source-selector">
        <ul>
          <li class="tab" data-language="CSharp">CSharp</li>
          <li class="tab" data-language="AnotherLanguage">AnotherLanguage</li>
        </ul>
        <div data-language="CSharp">
          <pre> ... </pre>
        </div>
        <div data-language="AnotherLanguage">
          <pre> ... </pre>
        </div>
      </div>
      <p>This is a different example which perhaps applies to just one language:</p>
      <div class="source-selector">
        <ul>
          <li class="tab" data-language="CSharp">CSharp</li>
        </ul>
        <div data-language="CSharp">
          <pre> ... </pre>
        </div>
      </div>
      <p>Another example:</p>
      <div class="source-selector">
        <ul>
          <li class="tab" data-language="CSharp">CSharp</li>
          <li class="tab" data-language="AnotherLanguage">AnotherLanguage</li>
          <li class="tab" data-language="YetAnotherLanguage">YetAnotherLanguage</li>
        </ul>
        <div data-language="CSharp">
          <pre> ... </pre>
        </div>
        <div data-language="AnotherLanguage">
          <pre> ... </pre>
        </div>
        <div data-language="YetAnotherLanguage">
          <pre> ... </pre>
        </div>
      </div>
    </div>