Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - multi step transformation >Thread Next - Re: multi step transformation Re: multi step transformationTo: NULL Date: 10/1/2004 11:18:00 PM Hi,
Staring with some well-formed XML like...
<?xml version="1.0"?>
<item>
<a>tom
dick
harry
peter</a>
<b>typeforA</b>
</item>
Something like...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<output>
<xsl:apply-templates select="item"/>
</output>
</xsl:template>
<xsl:template match="item">
<xsl:call-template name="splitA">
<xsl:with-param name="text" select="string(a)"/>
<xsl:with-param name="type" select="b"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="splitA">
<xsl:param name="text"/>
<xsl:param name="type"/>
<xsl:choose>
<xsl:when test="contains($text,' ')">
<a b="{$type}">
<xsl:value-of
select="normalize-space(substring-before($text,' '))"/>
</a>
<xsl:call-template name="splitA">
<xsl:with-param name="text"
select="substring-after($text,' ')"/>
<xsl:with-param name="type" select="$type"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="normalize-space($text)">
<a b="{$type}">
<xsl:value-of select="normalize-space($text)"/>
</a>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"wooks" <wookiz@h...> wrote in message
news:8852d33c.0410010840.2adad030@p......
> have
>
> <a>tom
> dick
> harry
> peter</a>
> <b>typeforA</b>
>
> I want
> <a b="typeforA>tom</a>
> <a b="typeforA>dick</a>
> <a b="typeforA>harry</a>
> <a b="typeforA>peter</a>
>
> I have a generic split routine that works but to get the output I want
> b has to be an attribute of a before the split routine runs. The split
> routine will then add b as an attribute to each A it creates.
>
> Obviously I could do this easily in a 2 step transform -
>
> 1. transform b from an element to an attribute of A.
> 2. Run the split.
>
> But I want to do it in one transform. How?
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
