[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT 2: Best Way to Synthesize Elements Given List

Subject: Re: XSLT 2: Best Way to Synthesize Elements Given List of Tagnames
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 5 Nov 2016 18:22:04 -0000
Re:  XSLT 2: Best Way to Synthesize Elements Given List
> Surely this doesn't satisy Eliot's requirement that the path can be "arbitrarily long"?
>
> Michael Kay


Yes, as well as the fact that probably every XML parser has a limit
for the maximum depth of an XML document that it can process.

Knowing this limit, one needs to make a more precise and realistic requirement.


Cheers,
Dimitre

On Sat, Nov 5, 2016 at 11:13 AM, Michael Kay mike@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> Surely this doesn't satisy Eliot's requirement that the path can be "arbitrarily long"?
>
> Michael Kay
> Saxonica
>
>> On 5 Nov 2016, at 16:50, Dimitre Novatchev dnovatchev@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>
>> I'd suggest this non-recursive solution:
>>
>> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>> <xsl:output omit-xml-declaration="yes" indent="yes"/>
>>
>> <xsl:param name="pPath" select="'/foo/bar/baz/bam/bak/bap/bah/baw'"/>
>>
>> <xsl:variable name="vNames" select="tokenize($pPath, '/')[.]"/>
>>
>> <xsl:template match="*[count(current()/ancestor::*) lt count($vNames)]">
>>   <xsl:element name="{$vNames[count(current()/ancestor::node())]}">
>>     <xsl:apply-templates select="*"/>
>>   </xsl:element>
>> </xsl:template>
>>
>> <xsl:template match="text()"/>
>> </xsl:stylesheet>
>>
>>
>> When applied on:
>>
>> <x1>
>> <x2>
>> <x3>
>>  <x4>
>>   <x5>
>>    <x6>
>>     <x7>
>>      <x8>
>>       <x9>
>>        <x10>
>>         <x11>
>>          <x12>
>>           <x13>
>>            <x14>
>>             <x15>
>>              <x16>
>>               <x17>
>>                <x18>
>>                 <x19>
>>                  <x20>
>>                  </x20>
>>                 </x19>
>>                </x18>
>>               </x17>
>>              </x16>
>>             </x15>
>>            </x14>
>>           </x13>
>>          </x12>
>>         </x11>
>>        </x10>
>>       </x9>
>>      </x8>
>>     </x7>
>>    </x6>
>>   </x5>
>>  </x4>
>> </x3>
>> </x2>
>> </x1>
>>
>> the result is:
>>
>> <foo>
>>  <bar>
>>     <baz>
>>        <bam>
>>           <bak>
>>              <bap>
>>                 <bah>
>>                    <baw/>
>>                 </bah>
>>              </bap>
>>           </bak>
>>        </bam>
>>     </baz>
>>  </bar>
>> </foo>
>>
>>
>> Cheers,
>> Dimitre
>>
>> On Sat, Nov 5, 2016 at 9:18 AM, Eliot Kimber ekimber@xxxxxxxxxxxx
>> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>> Say I have this string: "foo/bar" (or any arbitrarily-long sequence of
>>> /-delimited tag names) and want to construct from it:
>>>
>>> <foo>
>>> <bar>
>>>   <!-- Stuff added here that I get from somewhere else -->
>>> </bar>
>>> </foo>
>>>
>>> Is there an easier or more obvious way to generate this than an recursive
>>> function?
>>>
>>> With a recursive function I can easily create child elements until the
>>> sequence is exhausted but it feels like there should be an easier way
>>> using XSLT 2 but if there is I'm not thinking of it.
>>>
>>> Cheers,
>>>
>>> Eliot
>>>
>>> --
>>> Eliot Kimber
>>> http://contrext.com
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>> Cheers,
>> Dimitre Novatchev
>> ---------------------------------------
>> Truly great madness cannot be achieved without significant intelligence.
>> ---------------------------------------
>> To invent, you need a good imagination and a pile of junk
>> -------------------------------------
>> Never fight an inanimate object
>> -------------------------------------
>> To avoid situations in which you might make mistakes may be the
>> biggest mistake of all
>> ------------------------------------
>> Quality means doing it right when no one is looking.
>> -------------------------------------
>> You've achieved success in your field when you don't know whether what
>> you're doing is work or play
>> -------------------------------------
>> To achieve the impossible dream, try going to sleep.
>> -------------------------------------
>> Facts do not cease to exist because they are ignored.
>> -------------------------------------
>> Typing monkeys will write all Shakespeare's works in 200yrs.Will they
>> write all patents, too? :)
>> -------------------------------------
>> Sanity is madness put to good use.
>> -------------------------------------
>> I finally figured out the only reason to be alive is to enjoy it.
>>
> 



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.