Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - string to char conversion >Thread Next - Re: string to char conversion Re: string to char conversionTo: NULL Date: 3/3/2006 12:46:00 PM > Hello folks,
>
> I`m just racking my barin while trying to solve a simple problem:
> I need to converse a string ( which is an attribute`s value to the
> child elements of this element)
>
> This is my starting position:
>
> <LOOP value="OINK" />
>
> .. should be converted to :
>
> <LOOP [value="OINK"] > [...] = can remain if necessary, doesn`t care
> <char value="O"/>
> <char value="I"/>
> <char value="N"/>
> <char value="K"/>
> </LOOP>
>
> Sorry probably this is a pretty lousy problem, but I still try to solve
> such problems like in
> common programming languages, f.e. with a loop, but I had to find out
> it is not possible to increment variables, also a recursive called
> template didn`t work...
>
> Thanks a bomb for any help,
> Boris
Here you go:-
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" />
<xsl:template match="LOOP">
<LOOP>
<xsl:call-template name="doChar">
<xsl:with-param name="chars" select="@value" />
</xsl:call-template>
</LOOP>
</xsl:template>
<xsl:template name="doChar">
<xsl:param name="chars" />
<xsl:if test="string-length($chars) > 0">
<char value="{substring($chars, 1, 1)}" />
<xsl:call-template name="doChar">
<xsl:with-param name="chars" select="substring($chars, 2)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Anthony.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
