Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: creating new element from element [Thread Next] Re: creating new element from elementTo: NULL Date: 10/2/2008 7:46:00 AM On 2 Ott, 16:04, Martin Honnen <mahotr...@yahoo.de> wrote: > mariolon...@gmail.com wrote: > > I've the following xml file: > > > <myroot> > > =A0<element> > > =A0 =A0 <FirstSecondThree> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... some text or other = children elements ... > > =A0 =A0</FirstSecondThree> > > =A0</element> > > </myroot> > > > Is it possibile handling elements in compound-form? (FirstSecondThree) > > Is it possible by means of XSLT obtaining the xml file: > > <myroot> > > =A0<element> > > =A0 =A0 <Three> > > =A0 =A0 =A0 =A0<Second> > > =A0 =A0 =A0 =A0 =A0<First> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ... some text or other = children elements ... > > =A0 =A0 =A0 =A0 =A0</First> > > =A0 =A0 =A0 </Second> > > =A0 =A0</Three> > > =A0</element> > > </myroot> > > Here is a sample stylesheet using XSLT 2.0: > > <xsl:stylesheet > =A0 =A0xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" > =A0 =A0xmlns:xs=3D"http://www.w3.org/2001/XMLSchema" > =A0 =A0exclude-result-prefixes=3D"xs" > =A0 =A0version=3D"2.0"> > > =A0 =A0<xsl:strip-space elements=3D"*"/> > =A0 =A0<xsl:output method=3D"xml" indent=3D"yes"/> > > =A0 =A0<xsl:template match=3D"@* | node()"> > =A0 =A0 =A0<xsl:copy> > =A0 =A0 =A0 =A0<xsl:apply-templates select=3D"@* | node()"/> > =A0 =A0 =A0</xsl:copy> > =A0 =A0</xsl:template> > > =A0 =A0<xsl:template name=3D"nest-elements"> > =A0 =A0 =A0<xsl:param name=3D"name-items" as=3D"xs:string*"/> > =A0 =A0 =A0<xsl:choose> > =A0 =A0 =A0 =A0<xsl:when test=3D"not(empty($name-items))"> > =A0 =A0 =A0 =A0 =A0<xsl:element name=3D"{$name-items[1]}"> > =A0 =A0 =A0 =A0 =A0 =A0<xsl:call-template name=3D"nest-elements"> > =A0 =A0 =A0 =A0 =A0 =A0 =A0<xsl:with-param name=3D"name-items" > select=3D"$name-items[position() > 1]"/> > =A0 =A0 =A0 =A0 =A0 =A0</xsl:call-template> > =A0 =A0 =A0 =A0 =A0</xsl:element> > =A0 =A0 =A0 =A0</xsl:when> > =A0 =A0 =A0 =A0<xsl:otherwise> > =A0 =A0 =A0 =A0 =A0<xsl:apply-templates/> > =A0 =A0 =A0 =A0</xsl:otherwise> > =A0 =A0 =A0</xsl:choose> > =A0 =A0</xsl:template> > > =A0 =A0<xsl:template match=3D"FirstSecondThree"> > =A0 =A0 =A0<xsl:variable name=3D"re" select=3D"'\p{Lu}\p{Ll}+'"/> > =A0 =A0 =A0<xsl:variable name=3D"name-items" as=3D"xs:string+"> > =A0 =A0 =A0 =A0<xsl:analyze-string > =A0 =A0 =A0 =A0 =A0select=3D"local-name()" > =A0 =A0 =A0 =A0 =A0regex=3D"{$re}"> > =A0 =A0 =A0 =A0 =A0<xsl:matching-substring> > =A0 =A0 =A0 =A0 =A0 =A0<xsl:sequence select=3D"."/> > =A0 =A0 =A0 =A0 =A0</xsl:matching-substring> > =A0 =A0 =A0 =A0</xsl:analyze-string> > =A0 =A0 =A0</xsl:variable> > =A0 =A0 =A0<xsl:call-template name=3D"nest-elements"> > =A0 =A0 =A0 =A0<xsl:with-param name=3D"name-items" select=3D"reverse($nam= e-items)"/> > =A0 =A0 =A0</xsl:call-template> > =A0 =A0</xsl:template> > > </xsl:stylesheet> > > You can run XSLT 2.0 stylesheet with Saxon 9 > (http://saxon.sourceforge.net/), AltovaXML > (http://www.altova.com/altovaxml.html), and Gestalt > (http://gestalt.sourceforge.net/). > > If you want to do the same with XSLT 1.0 then please let us know which > XSLT processor you want to use as splitting up that string is a pain in > pure XSLT 1.0 so if we know the XSLT processor you use then we might be > able to make use of extension functions. > > -- > > =A0 =A0 =A0 =A0 Martin Honnen --- MVP XML > =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/ Thanks | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
