2016-07-01 6 views
0

こんにちは、私はXSL(T)に関して質問を受けました。元のテンプレートに影響を与えずにテンプレートを拡張することは可能ですか?コードで自分自身を説明させてください。XSL - すべてのオブジェクトを継承して拡張します。

私は、次の元のテンプレート(元-template.xsl)を持っている:

<xsl:template match="dom:Textbox"> 
     <xsl:attribute name="id"> 
     <xsl:value-of select="@id" /> 
     </xsl:attribute> 
     <xsl:choose> 
     <xsl:when test="@password = 'true'"> 
      <xsl:attribute name="type">password</xsl:attribute> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:attribute name="type">text</xsl:attribute> 
     </xsl:otherwise> 
     </xsl:choose> 
</xsl:template> 

今、私は拡張ファイル(extension.xsl)を持っているが却下するために作成または理想的な状況では、元のXSLファイルを拡張します:

<xsl:template match="dom:Textbox"> 
     <xsl:if test="@cssClass='placeholder-input'"> 
     <xsl:attribute name="placeholder">Enter your email</xsl:attribute> 
     </xsl:if> 
</xsl:template> 

これを実行すると、元のテンプレートに記載されているすべてのものが無効になります。元のテンプレートのすべてを継承し、プレースホルダコードを元のテンプレートに追加する方法はありますか?

+0

いいえ、テンプレートは拡張できません。なぜあなたはテンプレートを拡張する必要がありますか? 'dom:Textbox [@ cssClass = 'placeholder-input']'の行に沿って、より具体的なテンプレートを書くのはどうでしょうか?複数のテンプレートに共通するコードが多い場合は、_named_テンプレートを作成することを検討してください。 –

+0

'xsl:include'や' xsl:import'を使っていますか? 'xsl:import'を使っているのであれば、おそらく' xsl:apply-imports'を使ってインポートされたXSLTファイルにテンプレートを適用することができます。 –

答えて

0

xsl:importxsl:apply-importsでこれを行うことができます。あなたのextension.xsl使用<xsl:import href="original-template.xsl"/>を想定し、それはその後さらにXSLT 2.0はxsl:next-matchを持って

<xsl:template match="dom:Textbox"> 
     <xsl:if test="@cssClass='placeholder-input'"> 
     <xsl:attribute name="placeholder">Enter your email</xsl:attribute> 
     </xsl:if> 
     <xsl:apply-imports/> 
</xsl:template> 

を使用することができます。

関連する問題