2013-04-17 34 views
0

是否可以將所有內容節點存儲爲數組並傳遞給另一個模板?我已經嘗試過,但無法得到它的工作。我的選擇表達式是選擇正確的節點。在陣列中存儲節點

<xsl:variable name="array" select="/data/contents/content[ ..... ] /> 
    <xsl:value-of select="$array/.../... " /> 


    <xsl:variable name="bannerList" select="data/contents[$dayOfWeekIndex]/content[position() &lt;= 5]" /> 

    <xsl:apply-templates select="$bannerList" mode="article"> 
     <xsl:with-param name="numberOfBanners" select="count($bannerList)" /> 
    </xsl:apply-templates> 

我想使用呼叫模板,而不是發送bannerList作爲參數。

+0

您是否可以爲我們提供迄今爲止所擁有的示例? – JLRishe

+0

是的,你可以傳遞一個nodeset作爲參數,就像任何其他變量一樣:''。你的XSLT在哪裏不能按照你的預期工作? – JLRishe

+0

我得到了計數($ bannerList)= 1,正如我所料。但是,當我嘗試訪問另一個模板內的任何內容時select =「$ bannerList /.../@somthing」我得到一個空的結果。 – pethel

回答

1

是的,它很容易平易近人,看看:

XML:

<body> 
    <RIAssetType><text>Product</text></RIAssetType> 
    <RIAssetType><text>Service</text></RIAssetType> 
    <RIAssetType><text>Company/Business Unit</text></RIAssetType> 
    <RIAssetType><text>Technology</text></RIAssetType> 
    <RIAssetType><text>Intellectual Property/Data Only</text></RIAssetType> 
</body> 

XSLT:

<?xml version='1.0' ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="body"> 
    <copyBody> 
    <xsl:call-template name="childCopy"> 
     <xsl:with-param name="bodyChild" select="self::body/child::*"/> 
    </xsl:call-template> 
    </copyBody> 
    </xsl:template> 

    <xsl:template name="childCopy"> 
    <xsl:param name="bodyChild"/> 
    <xsl:for-each select="$bodyChild/self::*"> 
     <xsl:copy> 
     <xsl:copy-of select="."/> 
     </xsl:copy> 
    </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

OUTPUT:

<copyBody> 
    <RIAssetType> 
    <RIAssetType> 
     <text>Product</text> 
    </RIAssetType> 
    </RIAssetType> 
    <RIAssetType> 
    <RIAssetType> 
     <text>Service</text> 
    </RIAssetType> 
    </RIAssetType> 
    <RIAssetType> 
    <RIAssetType> 
     <text>Company/Business Unit</text> 
    </RIAssetType> 
    </RIAssetType> 
    <RIAssetType> 
    <RIAssetType> 
     <text>Technology</text> 
    </RIAssetType> 
    </RIAssetType> 
    <RIAssetType> 
    <RIAssetType> 
     <text>Intellectual Property/Data Only</text> 
    </RIAssetType> 
    </RIAssetType> 
</copyBody> 

看來你在XPATH的某處有struct,請再次檢查。