473,769 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

recursive xsl

Hi i'm new to xsl and i have been using smarty php templating but its
just so hard to read codes in smarty/php/flash than xml/xsl/flash, i
rather sacrifice speed then not being able to read code after 3 months.
So my problem goes like this.
I have an xml that like this
<avatar>
<avatarId>1</avatarId>
<avatarName>MyN ewAvatar</avatarName>
<avatarFile>
<fileName>MyNew Avatar.swf</fileName>
</avatarFile>
<avatarColor>
<color>
<colorId>1</colorId>
<colorName>BLUE </colorName>
</color>
<color>
<colorId>2</colorId>
<colorName>BLAC K</colorName>
</color>
<color>
<colorId>3</colorId>
<colorName>RE D</colorName>
</color>
<color>
<colorId>4</colorId>
<colorName>GREE N</colorName>
</color>
</avatarColor>
</avatar>

i want something like this
<div>
<div>BLUE BLACK</div>
<div><object ...... src="MyNewAvata r.swf" ... /></div>
<div>RED GREEN</div>
</div>

Is there a way to suspend the recursive loop say after 2 or more
colors? then go back to it the N +1 place? Any help would be big so i
need to thank you in advance...

Dec 20 '06 #1
5 1846

monmonja wrote:
<avatar>
<avatarId>1</avatarId>
<avatarName>MyN ewAvatar</avatarName>
<avatarFile>
<fileName>MyNew Avatar.swf</fileName>
</avatarFile>
<avatarColor>
<color>
<colorId>1</colorId>
<colorName>BLUE </colorName>
</color>
<color>
<colorId>2</colorId>
<colorName>BLAC K</colorName>
</color>
<color>
<colorId>3</colorId>
<colorName>RE D</colorName>
</color>
<color>
<colorId>4</colorId>
<colorName>GREE N</colorName>
</color>
</avatarColor>
</avatar>

i want something like this
<div>
<div>BLUE BLACK</div>
<div><object ...... src="MyNewAvata r.swf" ... /></div>
<div>RED GREEN</div>
</div>

Is there a way to suspend the recursive loop say after 2
or more colors? then go back to it the N +1 place?
I'm not sure what you mean and why do you need a recursive
loop in the first place. Something like the following
transformation should do the trick:

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="avatar">
<xsl:variable name="colors-1"
select=
"
avatarColor/color[colorId&gt;=1 and colorId&lt;=2]
"/>
<xsl:variable name="colors-2"
select=
"
avatarColor/color[colorId&gt;=3 and colorId&lt;=4]
"/>
<div>
<div>
<xsl:apply-templates
select="$colors-1" mode="color-names"/>
</div>
<div><object src="{avatarFil e/fileName}"/></div>
<div>
<xsl:apply-templates
select="$colors-2" mode="color-names"/>
</div>
</div>
</xsl:template>
<xsl:template match="color" mode="color-names">
<xsl:value-of select="colorNa me"/>
<xsl:text</xsl:text>
</xsl:template>
</xsl:stylesheet>

In case there's a good reason you need recursive loop, you
can always fiddle around with passing parameters on each
iteration: start-from, stop-at or somesuch.

--
Pavel Lepin

Dec 20 '06 #2
monmonja wrote:
Hi i'm new to xsl and i have been using smarty php templating but its
just so hard to read codes in smarty/php/flash than xml/xsl/flash, i
rather sacrifice speed then not being able to read code after 3 months.
If you are willing to look at languages other
than xsl, you might appreciate this solution in
XMLgawk:

@load xml
BEGIN { print "<div>" }
XMLCHARDATA { data = $0}
XMLENDELEM == "colorName" { color[++ci] = data }
XMLENDELEM == "fileName" { fileName = data }
ci == 2 {
print "<div>" color[1], color[2] "</div>" ;
print "<div><obje ct ...... src=\"" fileName "\" ... /></div>"
ci = 0
}
END { print "</div>" }
Readability of such scripts is in the eye of the beholder.
The output produced by this script looks like this:

<div>
<div>BLUE BLACK</div>
<div><object ...... src="MyNewAvata r.swf" ... /></div>
<div>RED GREEN</div>
<div><object ...... src="MyNewAvata r.swf" ... /></div>
</div>

I know this isnt exactly what you asked for, but it
is easy to change the script if you need different output.
Dec 20 '06 #3
The reason i need recursive because its more complex then that. Thanks
for the reply, can you show me a simple example of the passing
parameters on each
iteration: start-from, stop-at or somesuch.

BTW, php has more than 50 template systems, i cant afford to study one
again unless its a standard which XSL is. The reason ive used Smarty is
because it was here in my work when i came here.

Dec 21 '06 #4
Ive found the answer but i have another problem can someone explain to
this:
<xsl:template match="/">
<xsl:call-template name="tmpColors " >
<xsl:with-param name="counter" select="5" />
</xsl:call-template>
flash OBJECT
<xsl:apply-templates select="avatars/avatar/colors" />
</xsl:template>

<xsl:template match="avatars/avatar/colors" name="tmpColors ">
<xsl:param name="counter" />
<xsl:value-of select="count(c olor)" />
<xsl:for-each select="avatars/avatar/colors/color[position()
&lt; $counter]">
Try
<xsl:value-of select="colorna meame" />
<xsl:text</xsl:text>
</xsl:for-each>
</xsl:template>

On call-template count(color) = 0 while on apply-template count(color)
= n. but if i do XPath from the root down
count(avatars/avatar/colors/color) the opposite happens. Do
call-template use the match patterns? Any advice from the experts out
there when its more appropriate to use call-template over
apply-template. Again thanks in advance.

Dec 21 '06 #5

Please quote what you're replying to. (And if you start
quoting--don't top-post.) Read something about proper
etiquette when posting on the usenet.

monmonja wrote:
<xsl:template match="/">
<xsl:call-template name="tmpColors " >
<xsl:with-param name="counter" select="5" />
</xsl:call-template>
flash OBJECT
<xsl:apply-templates select="avatars/avatar/colors" />
</xsl:template>

<xsl:template match="avatars/avatar/colors"
name="tmpColors ">
<xsl:param name="counter" />
<xsl:value-of select="count(c olor)" />
<xsl:for-each
select="avatars/avatar/colors/color[position()
&lt; $counter]">
Try
<xsl:value-of select="colorna meame" />
<xsl:text</xsl:text>
</xsl:for-each>
</xsl:template>

On call-template count(color) = 0 while on apply-template
count(color) = n. but if i do XPath from the root down
count(avatars/avatar/colors/color) the opposite happens.
Do call-template use the match patterns?
No, they don't. (I remember vividly putting my foot in my
mouth regarding this a few months ago--and Joe Kesselman
gently biting my head off shortly thereafter. Ah, sweet
memories.) call-template simply invokes another template,
without changing the context node.
Any advice from the experts out there when its more
appropriate to use call-template over apply-template.
Again thanks in advance.
First of all, I'd say using the same template as both
matchable and callable is a bad idea. Naturally, there
might be certain situations where this would be
appropriate, but unless you have a very good reason to do
something like that--don't.

In terms of imperative programming it might help thinking
about named templates as something like functions, and
about templates invoked using apply-templates as
polymorphic methods. A named template doesn't really care
about the context it's invoked from: it just does some
largerly context-independent stuff and that's all. Applying
templates to a nodeset is similar to doing something with a
collection of objects that you know implement a certain
interface without really caring about implementations . You
just say: 'do-something with all these nodes', and the
templates matching the nodes in question will determine
precisely how it will be done.

--
Pavel Lepin

Dec 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
2293
by: Carlos Ribeiro | last post by:
Hello all, Here I am using some deeply nested, tree-like data structures. In some situations I need to traverse the tree; the old-style way to do it is to write a recursive method on the node class, as in: def walk(self): """old-style recursive tree traversal""" child.do_something for child in childs:
10
5674
by: Steve Goldman | last post by:
Hi, I am trying to come up with a way to develop all n-length permutations of a given list of values. The short function below seems to work, but I can't help thinking there's a better way. Not being a computer scientist, I find recursive functions to be frightening and unnatural. I'd appreciate if anyone can tell me the pythonic idiom to accomplish this. Thanks for your help,
2
2888
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays a sequence of spaces; recursive function 2 uses input to display ascending sequence of digits; likewise, recursive function 3 uses input to display descending sequence of digits. I have not followed the instructions completely regarding the...
7
567
by: Jon Slaughter | last post by:
#pragma once #include <vector> class empty_class { }; template <int _I, int _J, class _element, class _property> class RDES_T {
1
2392
by: Jon Slaughter | last post by:
I've managed to put together a template class that basicaly creates a recursive tree that lets you easily specify the "base" class of that tree and and ending notes and lets you stop the recursive process if you want. The problem now is to make a Type list so I can specify more than one node at a time to "attach" a class to. I think I will be able to handle this but I want to run the code by you guys to see there are any major design...
4
9054
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. However, it is not as straightforward to determine the base address for my stack space. The approach I have taken is to save the address of an automatic variable in main( ), and assume this is a fairly good indicator of my base address. Then, I can...
9
3328
by: seberino | last post by:
I'm a compiler newbie and curious if Python grammar is able to be parsed by a recursive descent parser or if it requires a more powerful algorithm. Chris
0
1959
by: champ1979 | last post by:
I wrote an algorithm to get all the relatives of a person in a family tree. I'm basically getting all the users from the DB and am doing the recursive logic in code, so that there is only 1 call made to the DB. However, I am trying to do the same thing within a stored procedure in SQL using recursive CTEs (I think the performance might be better) but I'm finding it really tough to craft the CTE. I would really appreciate if someone could...
18
4727
by: Just Another Victim of the Ambient Morality | last post by:
Is pyparsing really a recursive descent parser? I ask this because there are grammars it can't parse that my recursive descent parser would parse, should I have written one. For instance: from pyparsing import * grammar = OneOrMore(Word(alphas)) + Literal('end') grammar.parseString('First Second Third end')
3
4242
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular reference, which means it is only collected by the mark-and-sweep collector, not by reference counting. Here is some code that demonstrates it: === def outer():
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.