2014-11-06 198 views
0

我有一個XSL宏看起來像這樣: 同一個宏應該從2個不同的地方調用只差異是在for-each sellect其中「quickLinksUrls1」或「quickLinksUrls2」應該是調用。 我在考慮將它作爲變量發送,但不知道如何在每個變量中使用此參數。Umbraco XSLT for-每個循環與變量

如何實現這個沒有使兩個不同的宏幾乎相同的foreach循環?

<xsl:param name="currentPage"/> 
<xsl:param name="quickLinksGroup" select="/macro/quickLinksGroup"/> 

<xsl:template match="/"> 

    <xsl:for-each select="$currentPage/ancestor-or-self::*/Home/quickLinksUrls1/multi-url-picker/*"> 
     <xsl:variable name="nodeId" select="node-id"/> 
     <xsl:variable name="linkTitle" select="link-title"/> 

     <xsl:if test="number($nodeId) &gt; 0"> 
     </xsl:if> 
    </xsl:for-each> 

</xsl:template> 

回答

0

你應該已經顯示了一些你的輸入文件,更容易誤解。 無論如何,我會試着猜你正在嘗試做什麼。

只需使用模板匹配模式而不是<xsl:for-each>即可。

<xsl:template match="/">  
    <xsl:apply-templates select="$currentPage/ancestor-or-self::*/Home/*[name()= 'quickLinksUrl1' or name()='quickLinksUrl2']/multi-url-picker/*"/>  
</xsl:template> 

<xsl:template match="*"> 
     <!-- The content of your initial "for-each" statement --> 
     ... 
</xsl:template> 

如果你需要區分quickLinksUrl1 & 2之間的模板的身體,你可以使用一個<xsl:if> insinde的template甚至在match屬性。

通常,您應該更喜歡使用模板模式並將for-each的用法限制爲簡單情況。要記住,這是一個很好的竅門,恕我直言。