Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, April 2, 2016

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   -   - <![CDATA[ Poker Betting - Online Poker Betting Structures    ]]>       -   -            -     114   -   - <![CDATA[ Beginners' Poker - Poker Hand Ranking    ]]>       -   -            -     115   -   - <![CDATA[ Poker Terms - 4th Street and 5th Street    ]]>       -   -            -     116   -   - <![CDATA[ Popular Poker - The Popularity of Texas Hold'em    ]]>       -   -            -     364   -   - <![CDATA[ The Impact of Traditional Poker on Online Poker (and vice versa)    ]]>       -   -            -     365   -   - <![CDATA[ The Ultimate, Absolute Online Poker Scandal    ]]>       -   -                -   -   -   +     101   -   - <![CDATA[ Poker Betting - All-in On the Flop    ]]>       -   -            +     102   -   - <![CDATA[ Beginners' Poker - Choosing an Online Poker Room    ]]>       -   -            +     105   -   - <![CDATA[ Beginners' Poker - Choosing What Type of Poker to Play    ]]>       -   -            +     106   -   - <![CDATA[ Online Poker - Different Types of Online Poker    ]]>       -   -            +     109   -   - <![CDATA[ Online Poker - Opening an Account at an Online Poker Site    ]]>       -   -            +     111   -   - <![CDATA[ Beginners' Poker - Poker Glossary    ]]>       -   -            +     117   -   - <![CDATA[ Poker Betting - What is a Blind?    ]]>       -   -            -     118   -   - <![CDATA[ Poker Betting - What is an Ante?    ]]>       -   -            +     119   -   - <![CDATA[ Beginners Poker - What is Bluffing?    ]]>       -   -            -     120   -   - <![CDATA[ Poker Games - What is Community Card Poker?    ]]>       -   -            -     121   -   - <![CDATA[ Online Poker - What is Online Poker?    ]]>       -   -                                        

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

    Popular Posts

    Powered by Blogger.