[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: Ragulf Pickaxe <ragulf.pickaxe@xxxxxxxxx>
Date: Fri, 23 Sep 2005 15:14:41 +0200
expand pickaxe
On 9/23/05, Paolo Vaccari <vaccari@xxxxxxxxxxxx> wrote:
> Hi all,
> I'm trying to write an extension for an xml language that doesn't have
> a "loop" or "repeat" statement. Thus I have to write some XSLT code
> to expand my own <repeat> element.
> At the moment my best solution is the following.
<snip/>
> This is very bad, because I have to modify the <sometag> template,
> which has nothing to do with my extension.
> Anyone has a better idea?
> Thanks
> Paolo Vaccari


Hi Paolo,

I don't know what you want with the sometag element, so it is a little
hard answering that part. What I would do, though, is to move the
processing down to the elements that you are working with (so you have
better control over when to output "sometag").

The solution should also enable you to make more types of elements
(besides txt and img) without modification.

I don't know if this will meet your requirements.
It is untested, though

<xsl:template match="ax:repeat">
  <xsl:apply-templates select="sometag"/>
</xsl:template>

<xsl:template match="sometag">
  <xsl:apply-templates select="ax:items[1]" mode="first"/>
</xsl:template>

<xsl:template match="ax:items" mode="first">
  <xsl:param name="pos" select="'1'"/>

  <sometag>
    <xsl:element name="{@element}">
      <xsl:attribute name="src">
        <xsl:value-of select="ax:item[$pos]/@src"/>
      </xsl:attribute>
    </xsl:element>
    <xsl:apply-templates select="following-sibling::ax:items" mode="further">
      <xsl:with-param name="pos" select="$pos"/>
    </xsl:apply-templates>
  </sometag>

  <xsl:if test="ax:item[$pos+1]"> <!-- More items? -->
    <xsl:apply-templates select="ax:items[1]" mode="first">
      <xsl:with-param name="pos" select="$pos+1"/>
    </xsl:apply-templates>
  </xsl:if>
</xsl:template>

<xsl:template match="ax:items" mode="further">
  <xsl:param name="pos"/>
  <xsl:element name="{@element}">
    <xsl:attribute name="src">
      <xsl:value-of select="ax:item[$pos]/@src"/>
    </xsl:attribute>
  </xsl:element>
</xsl:template>

I hope this helps

Regards,
Ragulf Pickaxe :-)

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.