【问题标题】:problem with xsl apply-templatesxsl 应用模板的问题
【发布时间】:2009-12-14 15:53:55
【问题描述】:

似乎我的模板从未被调用,但 for 循环工作正常。

它打印“test”的次数与“car”节点存在的次数完全相同,但“doStuff”似乎没有被访问,并且“test2”从未输出。有什么想法吗?

<fo:table-body>
      <xsl:for-each select="car">
      test
  <xsl:apply-templates select="car" />
  </xsl:for-each>
</fo:table-body>

....

<xsl:template match="car">
<fo:table-row height="0.40cm">
test2
dostuff()....

【问题讨论】:

    标签: xml pdf xslt pdf-generation apache-fop


    【解决方案1】:

    那是因为您正在尝试应用嵌套汽车...

    for-each 已经改变了上下文,所以你必须在当前节点上应用模板:

    <xsl:apply-templates select="."/>
    

    【讨论】:

      【解决方案2】:

      在 for-each 中,“car”是活动节点,由于默认情况下 apply-templates 上的 select 属性搜索后代轴,因此它试图选择作为活动汽车子项的“car”元素元素。试试

      <xsl:apply-templates select="."/>
      

      改为。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-08
        • 1970-01-01
        • 2014-03-18
        • 1970-01-01
        • 2012-02-20
        • 2017-11-06
        相关资源
        最近更新 更多