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/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--