[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT recursion problem

Subject: Re: XSLT recursion problem
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Wed, 28 Sep 2005 10:22:28 +0200
xsl item
Hi Paolo,

Le mercredi 28 septembre 2005 ` 09:46 +0200, Paolo Vaccari a icrit :

> The real problem is that I don't want to have to know anything about 
> <sometag>. That is, I would be free to use (and nest!) whatever 
> non-proprietary tag inside my <repeat>, without modifing it.
> Probably there's no way in XSLT 1.0 (if it is, why creating tunnel in 
> 2.0 ;) , but if you see another solution...

You can do that in XSLT 1.0 using modes and a node-set extension:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:ax="http://dyomedea.com" xmlns:exsl="http://exslt.org/common"
    extension-element-prefixes="exsl">
    <xsl:template match="*|@*">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="ax:repeat" name="ax:repeat">
        <xsl:param name="index">1</xsl:param>
        <xsl:variable name="rtf">
            <xsl:apply-templates mode="ax:repeat">
                <xsl:with-param name="index" select="$index"/>
            </xsl:apply-templates>
        </xsl:variable>
        <xsl:apply-templates select="exsl:node-set($rtf)/*"/>
        <xsl:if test="$index &lt; count(*/ax:items[1]/ax:item)">
            <xsl:call-template name="ax:repeat">
                <xsl:with-param name="index" select="$index + 1"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>
    <xsl:template match="ax:items">
        <xsl:element name="{@element}">
            <xsl:apply-templates select="ax:item[1]"/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="ax:item">
        <xsl:attribute name="src">
            <xsl:value-of select="@src"/>
        </xsl:attribute>
    </xsl:template>
    <xsl:template match="*|@*" mode="ax:repeat">
        <xsl:param name="index"/>
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" mode="ax:repeat">
                <xsl:with-param name="index" select="$index"/>
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="ax:items" mode="ax:repeat">
        <xsl:param name="index"/>
        <xsl:copy>
            <xsl:apply-templates select="@*|ax:item[$index]" mode="ax:repeat">
                <xsl:with-param name="index" select="$index"/>
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Eric

-- 
Le premier annuaire des apiculteurs 100% XML!
                                                http://apiculteurs.info/
------------------------------------------------------------------------
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
(ISO) RELAX NG   ISBN:0-596-00421-4 http://oreilly.com/catalog/relax
(W3C) XML Schema ISBN:0-596-00252-1 http://oreilly.com/catalog/xmlschema
------------------------------------------------------------------------

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.