XSLT templates and recursion
XSLT templates and recursion
Im new to XSLT and am having some problems trying to format an XML document which has recursive nodes.
My XML Code:
Hopefully my XML shows:
- All
are nested with - An item can have either just attributes, or sub nodes
- The level to which
nodes are nested can be infinently deep
- - - -
- - -
- -
107 - - - - - -
114 - - - - - -
115 - - - - - -
116 - - - - - -
364 - - - - - -
365 - - - - - - - -
+ -
101 - - - - + -
102 - - - - + -
105 - - - - + -
106 - - - - + -
109 - - - - + -
111 - - - - + -
117 - - - - - -
118 - - - - + -
119 - - - - - -
120 - - - - - -
121 - - - -
The XSL code:
test
hi
Im trying to write the XSL so that every
node will render a
and every
node will render an .
The XSL needs to be recursive because i cant tell how deep the nested nodes will go.
Can anyone help?
Regards, Al
Answer by duffymo for XSLT templates and recursion
I think you can just write the XSL-T to match on
. The only way recursion would matter would be if you wanted to retain parent/child relationships. Matching on
will be sufficient if your requirement is to map each one to a bullet in an unordered list
Answer by Matt for XSLT templates and recursion
Would something like this be more what you're after?
-
Answer by Don Roby for XSLT templates and recursion
You should be able to do this without writing a loop, if I understand your needs correctly.
It's generally better to use a more declarative style, in this instance writing a template matching the
tag and converting it to a
and another matching
converting it to a . An
call inside both templates would supply the recursion.
Answer by Tomalak for XSLT templates and recursion
This is easy. The XSLT processor does all the recursion and the looping for you, all you need to do is to specify templates for nodes you want to handle.
The
always is the recursive/iterative step in XSLT. It takes any nodes that fit its select
expression and finds templates for them.
Your job is it to craft an appropriate select
expression, supply a template for every node you want to handle and otherwise get out of the way. ;-) Resist the urge to cram everything into one big template or use
just because it feels convenient - it is not. Separate templates create more reusable and maintainable, less deeply nested code, and XSLT processors are optimized for template handling, so this might even be the more efficient approach.
Answer by markusk for XSLT templates and recursion
The following stylesheet performs the specified formatting. Note the use of xsl:apply-templates
to recurse down the XML tree. See 5.4 Applying Template Rules for more information.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment