0
在一個相當複雜的xslt文件中,一些元素將被處理兩次。這由具有參數的模板完成。xslt通過所有應用模板調用傳遞參數
<xsl:template macht="x">
<xsl:param name="modus"/>
<!-- comon things to do for both cases -->
<xsl:choose>
<xsl:when test="$modus='case1'"> <!-- things to do in case 1 --> </xsl:when>
<xsl:when test="$modus='case2'"> <!-- things to do in case 2 --> </xsl:when>
</xsl:choose>
</xsl:template>
的問題是:我不能簡單地套用或直接調用這個模板。元素x(這個模板有這兩種情況)適用於xml輸入。幾乎所有的祖先元素在它實際到達x之前都必須進行處理(在這兩種情況下)。
這兩個案件的調用是在最高級別。 在HTML它會是這樣
<body>
<h1>Case 1</h1>
<xsl:apply-templates><xsl:with-parameter name="modus" select="case1"/>
<h1>Case 2</h1>
<xsl:apply-templates><xsl:with-parameter name="modus" select="case2"/>
</body>
所以。我怎樣才能確保參數到達x的模板?
當然,我可以
<xsl:param name="modus">
<!-- What ever content here -->
<xsl:apply-templates><xsl:with-parameter name="modus" select="$modus"/></apply-templates>
取代對x的每一個祖先元素模板內的所有
<xsl:apply-templates/>
調用但是,這將意味着很多的努力。有一個更好的方法嗎?