0

3 つのノードのいずれかで xml を取得できます。

<root>
  <headerA>
    <!-- Content -->
  </headerA>
</root>

の代わりに、類似したコンテンツを持つノードまたはノード<headerA>が存在する可能性があります。この場合、html出力を次のようにします。<headerB><headerС>

<span> Type [X] </span> 

[X]要素のタグ名に応じて、A、B、または C はどこにありますか。

4

2 に答える 2

1

トマラクがすでに観察しているように、あなたの質問はかなり漠然としています。3 種類のヘッダーに対して 1 つのテンプレートを作成する方法を尋ねているように思えます。

<xsl:template match="headerA | headerB | headerC">
  <span>
    <xsl:apply-templates/>
  </span>
</xsl:template>

または、類似しているが異なるテンプレートを作成する方法:

<xsl:template match="headerA">
    <span> Type A </span>
</xsl:template>
<xsl:template match="headerB">
    <span> Type B </span>
</xsl:template>
<!--* Template for headerC left as an exercise for the reader *-->

または、一致するものに基づいてわずかに異なることを行う単一のテンプレートを作成する方法:

<xsl:template match="headerA | headerB | headerC">
  <span>
    <xsl:choose>
      <xsl:when test="self::headerA">
         <xsl:text> Type A </xsl:type>
      </xsl:when>
      <xsl:when test="self::headerB">
         <xsl:text> Type B </xsl:type>
      </xsl:when>
      <!--* etc. *-->
      <xsl:otherwise>
        <xsl:message terminate="yes"
          >I thought this could not happen.</xsl:message>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates/>
  </span>
</xsl:template>

これらのどれが役立つかがわかれば、何を質問しようとしているのかをより理解できるようになります。

于 2013-06-23T15:37:08.157 に答える
0
<xsl:template match="*[starts-with(name(), 'header')]">
  <xsl:variable name="type" select="substring-after(name(), 'header')" />
  <span>
    <xsl:value-of select="concat(' Type ', $type, ' ')" />
  </span>
</xsl:template>

これは、任意の文字列である という名前の任意の要素に対して機能しheaderXますX

于 2013-06-23T15:37:52.200 に答える