Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: creating new element from element

From: "Dimitre Novatchev" <dnovatchev@-----.--->
To: NULL
Date: 10/4/2008 8:33:00 AM

>   <xsl:template match="FirstSecondThree">
>     <xsl:variable name="re" select="'\p{Lu}\p{Ll}+'"/>
>     <xsl:variable name="name-items" as="xs:string+">
>       <xsl:analyze-string
>         select="local-name()"
>         regex="{$re}">
>         <xsl:matching-substring>
>           <xsl:sequence select="."/>
>         </xsl:matching-substring>
>       </xsl:analyze-string>
>     </xsl:variable>
>     <xsl:call-template name="nest-elements">
>       <xsl:with-param name="name-items" select="reverse($name-items)"/>
>     </xsl:call-template>
>   </xsl:template>

Martin,

you already know that the element name is exactly "FirstSecondThree".

Therefore, no further analysis (splitting) is necessary, just create an 
element named "Three" with a child named "Second" with a child named 
"First".


Such splitting (when really necessary) has been done in XSLT in a natural 
way, using the FXSL library. See an example here:

    http://markmail.org/message/dc6p5x6uiys2ag6q

Cheers,
Dimitre Novatchev


"Martin Honnen" <mahotrash@y...> wrote in message 
news:eEdERfJJJHA.5088@T......
> mariolongos@g... wrote:
>
>> I've the following xml file:
>>
>> <myroot>
>>  <element>
>>     <FirstSecondThree>
>>                         ... some text or other children elements ...
>>    </FirstSecondThree>
>>  </element>
>> </myroot>
>>
>> Is it possibile handling elements in compound-form? (FirstSecondThree)
>> Is it possible by means of XSLT obtaining the xml file:
>> <myroot>
>>  <element>
>>     <Three>
>>        <Second>
>>          <First>
>>                         ... some text or other children elements ...
>>          </First>
>>       </Second>
>>    </Three>
>>  </element>
>> </myroot>
>
> Here is a sample stylesheet using XSLT 2.0:
>
> <xsl:stylesheet
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:xs="http://www.w3.org/2001/XMLSchema"
>   exclude-result-prefixes="xs"
>   version="2.0">
>
>   <xsl:strip-space elements="*"/>
>   <xsl:output method="xml" indent="yes"/>
>
>   <xsl:template match="@* | node()">
>     <xsl:copy>
>       <xsl:apply-templates select="@* | node()"/>
>     </xsl:copy>
>   </xsl:template>
>
>
>   <xsl:template name="nest-elements">
>     <xsl:param name="name-items" as="xs:string*"/>
>     <xsl:choose>
>       <xsl:when test="not(empty($name-items))">
>         <xsl:element name="{$name-items[1]}">
>           <xsl:call-template name="nest-elements">
>             <xsl:with-param name="name-items" 
> select="$name-items[position() &gt; 1]"/>
>           </xsl:call-template>
>         </xsl:element>
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:apply-templates/>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
>
>   <xsl:template match="FirstSecondThree">
>     <xsl:variable name="re" select="'\p{Lu}\p{Ll}+'"/>
>     <xsl:variable name="name-items" as="xs:string+">
>       <xsl:analyze-string
>         select="local-name()"
>         regex="{$re}">
>         <xsl:matching-substring>
>           <xsl:sequence select="."/>
>         </xsl:matching-substring>
>       </xsl:analyze-string>
>     </xsl:variable>
>     <xsl:call-template name="nest-elements">
>       <xsl:with-param name="name-items" select="reverse($name-items)"/>
>     </xsl:call-template>
>   </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.
>
>
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 




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