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

Re: changing source-tree

Subject: Re: changing source-tree
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Nov 2005 14:27:13 +0000
jeni split
Hi Manuel,

> I have the following problem:
> <foo>
>      <example_bar>
>      ...
>      </example_bar>
> </foo>
>
> foo triggers a template which splits a string into one or more
> pieces. example_bar is the element which describes on how to output
> one of them. Though I only know at runtime how many pieces there
> are.

I'd pass the <example_bar> element as a parameter to the template that
splits the string into pieces, and then, within that template, apply
templates to the <example_bar> element with the substring as the
argument.

Something like:

<xsl:template match="foo">
  <xsl:call-template name="split-string">
    <xsl:with-param name="string" select="..." />
    <xsl:with-param name="output-template" select="*" />
  </xsl:call-template>
</xsl:template>

<xsl:template name="split-string">
  <xsl:param name="string" />
  <xsl:param name="output-template" />
  <xsl:choose>
    <xsl:when test="contains($string, ' ')">
      <!-- deal with the substring based on the output template -->
      <xsl:apply-templates select="$output-template">
        <xsl:with-param name="string"
                        select="substring-before($string, ' ')" />
      </xsl:apply-templates>
      
      <!-- recurse through the rest of the string -->
      <xsl:call-template name="split-string">
        <xsl:with-param name="string"
                        select="substring-after($string, ' ')" />
        <xsl:with-param name="output-template"
                        select="$output-template" />
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="$string">
      <!-- deal with the string based on the output template -->
      <xsl:apply-templates select="$output-template">
        <xsl:with-param name="string" select="$string" />
      </xsl:apply-templates>
    </xsl:when>
  </xsl:choose>
</xsl:template>

<xsl:template match="foo/*">
  <xsl:param name="string" />
  <xsl:copy>
    <xsl:value-of select="$string" />
  </xsl:copy>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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.