【问题标题】:XSL For Each - PathXSL For Each - 路径
【发布时间】:2014-12-24 15:02:47
【问题描述】:

我有一个如下所示的 XML 文件

- <alert>
   - <adv_details>
      <type>Primary Type</type> 
      <name>Some Name</name> 
      <id>ID Num</id>
     <adv_details>
     .....
  <alert> 

我的 XSL 看起来像这样

<fo:flow flow-name="xsl-region-body">
    <xsl:attribute name="font-size"><xsl:value-of select="$font-size"/></xsl:attribute>
    <fo:block>
        <xsl:for-each select="//alert">         
        <xsl:call-template name="alert_details">
            <xsl:with-param name="xmlSection" select="./alert_details"/>
        </xsl:call-template>
      ......

然后我尝试到达节点&lt;adv_details&gt; 内元素的每个值。 首先我声明这个模板名称&lt;xsl:template name="alert_details"&gt;,整个代码是

<xsl:template name="alert_details">
<fo:table>
   <fo:table-body>
      <fo:table-row>
        <fo:table-cell>
            <fo:block > 
                <xsl:value-of select="./@type"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block >
                <xsl:value-of select="./@name"/>
            </fo:block>
        </fo:table-cell>
        <fo:table-cell>
            <fo:block >
                <xsl:value-of select="./id"/>
            </fo:block>
        </fo:table-cell>
      </fo:table-row>
   </fo:table-body>
</fo:table>
</xsl:template>

它不显示值! 我认为这是一个正确的方法。首先,我有 for-each select="//alert,然后我有 &lt;xsl:with-param name="xmlSection" select="./alert_details"/&gt;,最后,我选择了 alert_details 中的每个节点,但不知何故,这些值没有显示出来。

请帮忙。

【问题讨论】:

    标签: xml xslt


    【解决方案1】:

    在您的模板中,上下文节点(= . 表达式)是 &lt;alert&gt; 元素。 实际上你要查询 xmlSection 参数的 type 子元素。 因此,在模板中显式声明参数 xmlSection:

    <xsl:template name="alert_details">
      <xsl:param name="xmlSection"/>
      ...
    

    并在您的选择中使用它:

    <xsl:value-of select="$xmlSection/type"/>
    

    【讨论】:

    • 非常感谢 NLips!请让我更清楚一点,我们不需要 `
    猜你喜欢
    • 2011-10-30
    • 2012-10-11
    • 2016-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 1970-01-01
    • 2023-01-11
    相关资源
    最近更新 更多