Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: string to char conversion

From: "Anthony Jones" <Ant@------------.--->
To: 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.





transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent