繁体   English   中英

XSLT 1.0-提取节点集并作为参数传递

[英]XSLT 1.0 - extract node-set and pass as param

我已经获得了这个XML,并且必须从中渲染很多,并且大多数都可以正常工作,但是我试图提取color的节点集(其keybar元素的键匹配,并且该属性是一个硬编码的字符串(在这种情况下为'data' )。 节点集将作为参数传递给模板,并且每条颜色线只能出现一次:

<report>
    <settings>
        <colors>
            <color key="1-1" name="frame" value="..." ... />
            <color key="1-1" name="data" value="..." ... />
            <color key="2-1" name="frame" value="..." ... />
            <color key="2-1" name="data" value="..." ... />
            <color key="3-1" name="frame" value="..." ... />
            <color key="3-1" name="data" value="..." ... />
        </colors>
        <comp>
             <cont>
                  <bar key="1-1" .../>
                  <bar key="1-1" .../>
                  <bar key="2-1" .../>
             </cont>
        <comp>
        <!-- possibly more <comp/cont/bar> below that may not be mixed with the above -->
     </settings>
</report>

在我的XSLT文件中,有以下内容(摘录):

<xsl:key name="barnode" match="bar" use="@key"/>
<xsl:key name="colorlookup" match="/report/settings/colors/color" use="@key"/>

<!-- this runs at the `cont` element level, i.e. `bar` can be accessed without prefix -->

<!-- set $x to the node-list of bars with unique @key attribute -->
<xsl:call-template name="renderit">
    <xsl:with-param name="colors">
        <!-- 'bars' contains node-set of 'bar' elements with @key being unique -->
        <xsl:variable name="bars" select="bar[generate-id() = generate-id(key('barnode', @key)[1])]"/>
        <xsl:for-each select="$bars">
            <xsl:value-of select="key('colorlookup', @key)[@name='data']"/>
        </xsl:for-each>
    </xsl:with-param>
</xsl:call-template>

问题在于,这不会传递节点集,而是传递树片段。 是否可以进行与上述相同的选择,但返回节点集?

编辑:

预期的节点集:

<color key="1-1" name="data" value="..." ... />
<color key="2-1" name="data" value="..." ... />

我不确定给出的XSLT是否会生成此结果树片段,因为我不知道如何打印(出于调试目的)。

尝试

<xsl:with-param name="colors" select="key('colorlookup', bar[generate-id() = generate-id(key('barnode', @key)[1])]/@key)[@name = 'data']"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM