Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 22nd, 2007, 01:14 PM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pretty nested printing with XSLT

Hi,

I'm interested in generating C++ code recursively.

I have this "recursive definition"

<recdefine>
 <expression type="OR">
   <expression type="AND">
    <expression type="int"/>
    <expression type="string"/>
    <expression type="int"/>
   </expression>
   <expression type="AND">
    <expression type="float"/>
    <expression type="int"/>
   </expression>
   <expression type="float"/>
 </expression>
</recdefine>

And I want it to generate C++ code similiar to this:

... = new Definition (
                      new ORExpr(
                                 new ANDExpr(
                                             new INTExpr(),
                                             new STRINGExpr(),
                                             new INTExpr()
                                             )
                                 ,
                                 new ANDExpr(
                                             new FLOATExpr(),
                                             new INTExpr()
                                             )
                                 ,
                                 new FLOATExpr()
                                 )
                      );

I am able to generate recursive code such as the above with ease.
However my problem is getting the "pretty" nesting. I just get some bad jumble that is hard to look at.

Any ideas on how to do that?

Thanks

 
Old August 23rd, 2007, 02:07 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

Assuming you're using templates, you could have a padding parameter, and add more spaces to the parameter everytime you apply-templates. eg
<xsl:template match="someNode">
<xsl:param name="padding" select="''"/>
<xsl:value-of select="$padding"/>
...
<xsl:apply-templates>
  <xsl:with-param name="padding" select="concat($padding, ' ')"/>
</xsl:apply-templates>

One drawback is that you might have to add it in multiple places.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding nested elements XSLT 1? Budbertzerofluff XSLT 2 November 15th, 2008 02:45 PM
Nested For-Each Loop In XSLT dghosh XSLT 10 July 2nd, 2008 04:34 AM
XSLT Nested For-Each mastermindg XSLT 2 December 21st, 2006 08:17 PM
Fanfold page printing using XSLT rajendra_mrprasad XSLT 0 May 9th, 2006 09:38 AM
XSLT and Printing buttergrooves XSLT 0 April 11th, 2005 04:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.