2011-12-02 9 views
2

call-template要素のname属性でXpathを使用できないようです。どうすればこの問題を回避できますか?どんな助けや考えも素晴らしいでしょう!XSLT呼び出しテンプレートの名前属性

<xsl:for-each select="child::knomaddb/Content/Videos"> 
     <xsl:result-document method="xhtml" href="{local-name()}.html"> 
      <html> 
       <body> 
        <h1>Knomad</h1> 
        <h2>{local-name()} Videos</h2> 
        <table border="1"> 
         <tr bgcolor="#9acd32"> 
          <th>Title</th> 
          <th>Video</th> 
          <th>Description</th> 
          <th>Comments</th> 
         </tr> 
         <xsl:for-each select="Video"> 
          <xsl:call-template name="{ancestor::local-name()}"/> 
         </xsl:for-each> 
        </table> 
       </body> 
      </html> 
     </xsl:result-document> 
    </xsl:for-each> 
+3

問題を解決するために適用テンプレートとテンプレートルールを試したことがありますか? call-template命令は、name属性のxpath式を受け入れません。明示的に名前を設定する必要があります。 – riff

+0

XPath式ancestor :: local-name()は有効なXPath式ではなく、おそらく複数の名前を選択する場合は、xsl:apply-templatesを再作成しようとしているようですが、ノードには複数の祖先があるためです。 –

答えて

1

私は コール-template要素のname属性でXPathを使用傾けるかのように思えます。どうすればこの問題を回避できますか?

良い質問、+1。

できません。しかし、代わりに<xsl:apply-templates>を使用することができます。

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:double="double" xmlns:incr="incr" xmlns:my="my:my" 
exclude-result-prefixes="double incr my" 
> 
    <xsl:output method="text"/> 

    <double:double/> 
    <incr:incr/> 

    <xsl:variable name="vFuncDouble" 
     select="document('')/*/double:*[1]"/> 

    <xsl:variable name="vFuncIncr" 
     select="document('')/*/incr:*[1]"/> 

    <xsl:function name="my:double"> 
    <xsl:param name="arg1" /> 

     <xsl:sequence select="2*$arg1"/> 
    </xsl:function> 

    <xsl:function name="my:incr"> 
    <xsl:param name="arg1" /> 

     <xsl:sequence select="1+$arg1"/> 
    </xsl:function> 

    <xsl:template name="double" match="double:*"> 
     <xsl:param name="arg1"/> 

     <xsl:sequence select="my:double($arg1)"/> 
    </xsl:template> 

    <xsl:template name="incr" match="incr:*"> 
     <xsl:param name="arg1"/> 

     <xsl:sequence select="my:incr($arg1)"/> 
    </xsl:template> 

    <xsl:function name="my:apply"> 
     <xsl:param name="pFun" as="element()"/> 
     <xsl:param name="arg1"/> 

     <xsl:apply-templates select="$pFun"> 
     <xsl:with-param name="arg1" select="$arg1"/> 
     </xsl:apply-templates> 
    </xsl:function> 

    <xsl:template match="/"> 
    <xsl:sequence select="my:apply($vFuncIncr, my:apply($vFuncDouble,2))"/> 
    </xsl:template> 
</xsl:stylesheet> 

この変換は、(使用しない)任意のXML文書に適用されると、希望の結果が生成されます:

5 

はメモしています。ここ

は、迅速なデモです

パラメタとして渡すことができます(最初の引数)をmy:apply()の「関数」に、my:apply()に設定すると、2番目の引数に適用されます。 read more here - XSLT 1.0とXSLT 2.0でこれと同じ原理the FXSL library実装高階関数(HOFs)を使用して

。今後XPath 3.0機能する

Xpath Data Modelで初めてファーストクラスのオブジェクト(XDM)です。

関連する問題