|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: mixing recursive template calls and for-each
Thanks very much, it works. I fell into the "all in one template" solution while struggling with my problem... I could not think of passing the current item all along during the process. Also i thought xsl:with-param could only be used with xsl:call-template. Let me recall the problem and its solution for those interested : Original file : <page xmlns:place="http://place.noce.fr/1.0"> <place:list-of node="workitem"> <!-- iterate over the workitem node which is inside source --> <source> <workitems> <workitem> <name>wi_1</name> <description>desc_wi_1</description> </workitem> <workitem> <name>wi_2</name> <description>desc_wi_2</description> </workitem> </workitems> </source> <link> <text><place:value-of name="description" /></text> <!-- replace with value of description node of workitem --> <url><place:value-of name="name" /></url> </link> </place:list-of> </page> I would like to transform this file into an XML file which looks like this : <page> <link> <text>desc_wi_1</text> <url>wi_1</url> </link> <link> <text>desc_wi_2</text> <url>wi_2</url> </link> </page> The correct stylesheet has the following templates : <xsl:template match="place:list-of">
<xsl:variable name="element" select="@node" />
<xsl:variable name="items"
select="source//*[name() = $element]" />
<xsl:variable name="template" select="*[position() >= 2]" />
<xsl:for-each select="$items">
<xsl:apply-templates select="$template">
<xsl:with-param name="item" select="." />
</xsl:apply-templates>
</xsl:for-each>
</xsl:template> <xsl:template match="place:value-of">
<xsl:param name="item" select="/.." />
<xsl:variable name="element" select="@name" />
<xsl:value-of select="$item/*[name() = $element]" />
</xsl:template> <xsl:template match="node()|@*">
<xsl:param name="item" select="/.." />
<xsl:copy>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="item" select="$item" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>Yvan -- ------------------------------------------------------------------ | Yvan Peter | phone (33) 3.20.43.32.64 | | CUEEP/Laboratoire TRIGONE | fax (33) 3.20.43.32.79 | | Bat. B6 | mail Yvan.Peter@xxxxxxxxxxxxxx | | Cite Scientifique | | | 59655 Villeneuve d'Ascq Cedex | | ------------------------------------------------------------------ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








