Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - string methods n xsl [Thread Next] Re: string methods n xslTo: NULL Date: 10/1/2004 2:07:00 AM Hi, > is there any way to do string methods in xsl? e.g. string splitting and > string concatination? e.g. Yes... substring(), substring-after() and substring-before() functions for splitting... and the concat() function for concatenation. None of which would be particularly useful, on their own, in your hypothetical example... specifically, you'd never have to use the concat() function for either process. The concat() function is way over used by many XSLT programmers - and is often a tautology of what the transformation engine was intending to do anyway... serialize the output. Try these stylesheets... <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/foos"> <abc> <xsl:apply-templates/> </abc> </xsl:template> <xsl:template match="a | b | c"> <xsl:copy> <xsl:attribute name="foos"> <xsl:for-each select="*"> <xsl:value-of select="name()"/> <xsl:if test="position() != last()"> <xsl:text>_</xsl:text> </xsl:if> </xsl:for-each> </xsl:attribute> </xsl:copy> </xsl:template> </xsl:stylesheet> and... <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/abc"> <foos> <xsl:apply-templates/> </foos> </xsl:template> <xsl:template match="a | b | c"> <xsl:copy> <xsl:call-template name="split-foo-att"> <xsl:with-param name="foo-att" select="@foos"/> </xsl:call-template> <xsl:attribute name="foos"> <xsl:for-each select="*"> <xsl:value-of select="name()"/> <xsl:if test="position() != last()"> <xsl:text>_</xsl:text> </xsl:if> </xsl:for-each> </xsl:attribute> </xsl:copy> </xsl:template> <xsl:template name="split-foo-att"> <xsl:param name="foo-att"/> <xsl:choose> <xsl:when test="contains($foo-att,'_')"> <xsl:element name="{substring-before($foo-att,'_')}"/> <xsl:call-template name="split-foo-att"> <xsl:with-param name="foo-att" select="substring-after($foo-att,'_')"/> </xsl:call-template> </xsl:when> <xsl:when test="normalize-space($foo-att)"> <xsl:element name="{$foo-att}"/> </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 "Daniel" <softwareengineer98037@y...> wrote in message news:eLczOx0pEHA.2456@T...... > is there any way to do string methods in xsl? e.g. string splitting and > string concatination? e.g. > > convert: > ______________________________________ > <foos> > <a> > <abh/> > <def/> > <ghi/> > </a> > <b> > <ccc/> > <ddd/> > <eee/> > </b> > <c> > <xxx/> > <yyy/> > <zzz/> > </c> > </foos> > ______________________________________ > > to > ______________________________________ > <abc> > <a foo="abh_def_ghi"> > <b foo="ccc_ddd_eee"> > <c foo="xxx_yyy_zzz"> > </abc> > ______________________________________ > > or vise-versa > > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
