समस्या उस कोड में है जिसे आपने हमें नहीं दिखाया है। इस श्रृंखला/पाइप टेम्पलेट्स के लिए एक सही तरीका है, हालांकि मैं, इसकी सलाह नहीं होगा (इस जवाब के अंत में देखें)
यह परिवर्तन:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:call-template name="loop">
<xsl:with-param name="times" select="3"/>
<xsl:with-param name="output">
<xsl:call-template name="foo">
<xsl:with-param name="pN" select="5"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="loop">
<xsl:param name="times" select="1"/>
<xsl:param name="output" select="2"/>
<xsl:choose>
<xsl:when test="not($times > 0)">
<xsl:value-of select="$output"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="loop">
<xsl:with-param name="times" select="$times -1"/>
<xsl:with-param name="output" select="2*$output"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="foo">
<xsl:param name="pN" select="1"/>
<xsl:value-of select="2*$pN"/>
</xsl:template>
</xsl:stylesheet>
जब किसी भी एक्सएमएल (नहीं पर लागू
80
शैली संबंधी सिफारिश: प्रयुक्त), चाहता था, सही परिणाम पैदा करता
इस तरह से चेनिंग टेम्पलेट से बचने का प्रयास करें क्योंकि यह परिणाम अपठनीय और अनजान कोड में हैं।
इंटरमीडिएट परिणाम (सही ढंग से नामित) चर प्राप्त करना बेहतर है। कोड न केवल इस तरह से अधिक पठनीय और रखरखाव योग्य है, लेकिन किसी भी मध्यवर्ती परिणाम को फिर से मूल्यांकन करने की आवश्यकता के बिना कई बार फिर से उपयोग किया जा सकता है।
यहाँ एक ही परिवर्तन है, लेकिन सिफारिश की शैलीगत आवश्यकताओं को पूरा करने पर निर्भर करता:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:variable name="vTwice">
<xsl:call-template name="twice">
<xsl:with-param name="pN" select="5"/>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="loop">
<xsl:with-param name="pTtimes" select="3"/>
<xsl:with-param name="pN" select="$vTwice"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="loop">
<xsl:param name="pTtimes" select="1"/>
<xsl:param name="pN" select="2"/>
<xsl:choose>
<xsl:when test="not($pTtimes > 0)">
<xsl:value-of select="$pN"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="loop">
<xsl:with-param name="pTtimes" select="$pTtimes -1"/>
<xsl:with-param name="pN" select="2*$pN"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="twice">
<xsl:param name="pN" select="1"/>
<xsl:value-of select="2*$pN"/>
</xsl:template>
</xsl:stylesheet>
स्रोत
2010-10-24 15:29:54
अच्छा सवाल है, +1। अपने प्रदत्त कोड के कुछ उदाहरण और कुछ अनुशंसाओं के लिए मेरा उत्तर देखें। –