0

したがって、XSLT のアイデンティティ デザイン パターンを使用しています。

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()[not(@visible='false')]"/>
  </xsl:copy>
</xsl:template>

そして、さまざまなノードに一致する多くのテンプレートがあります。今私がやりたいことは、1 つの xsl:template 内にいくつかのコードを生成し、別の xsl:template を新たに生成されたコードと一致させることです。これを行う方法を知っている人はいますか?


私がやりたいことの例:

<xsl:template match="button">
     <a href="@url" class="button"> <xsl:value-of select="@name" /> </a>
</xsl:template>

<xsl:template match="stuff">
    <!-- do some stuff -->
    <!-- get this following line parsed by the template over! -->
    <button url="something" name="a button" />
</xsl:template>
4

2 に答える 2

3

あなたがしようとしている方法でやりたいことを完全に行うことはできませんが、意図がコードを再利用してテンプレートの重複を避けることである場合、一致するテンプレートを名前付きテンプレートとして呼び出すことは完全に受け入れられます。パラメータも。

<xsl:template match="button" name="button"> 
   <xsl:param name="url" select="@url" />
   <xsl:param name="name" select="@name" />
   <a href="{$url}" class="button"> <xsl:value-of select="$name" /> </a> 
</xsl:template> 

したがって、ここでボタン要素に一致する場合は、urlおよびname属性をデフォルト値として使用しますが、名前付きテンプレートとして呼び出す場合は、独自のパラメーターを渡すことができます

<xsl:template match="stuff"> 
   <!-- do some stuff --> 
   <!-- get this following line parsed by the template over! --> 
   <xsl:call-template name="button">
    <xsl:with-param name="url" select="'something'" /> 
    <xsl:with-param name="name" select="'A button'" /> 
   </xsl:call-template> 
</xsl:template> 
于 2012-05-08T19:42:24.207 に答える
1

node-set()拡張機能を使用して、いくつかのマルチパス処理を実行できるはずです。

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/*">
    <xsl:variable name="first_pass">
      <xsl:apply-templates select="button" />
    </xsl:variable>

    <xsl:apply-templates mode="second_pass" select="ext:node-set($first_pass)/*" />
  </xsl:template>

  <xsl:template match="button">
    <a href="@url" class="button"> <xsl:value-of select="@name" /> </a>
  </xsl:template>

  <xsl:template match="stuff" mode="second_pass">
    <!-- do some stuff -->
    <!-- get this following line parsed by the template over! -->
    <button url="something" name="a button" />
  </xsl:template>
</xsl:stylesheet>

XSLTの最初の回答で詳細を取得できます-呼び出しテンプレートの結果にテンプレートを適用します

于 2012-05-09T02:06:19.563 に答える