problem with xsl:for-each whitespace

Discussion in 'XML' started by f, Nov 19, 2003.

  1. f

    f Guest

    I am writing a java code generation tool. I use xml and xslt. But I
    have some problem using xsl:for-each.

    here is my xml
    <?xml version = "1.0"?>
    <CLASS
    package_name=".test"
    name="TestAnalysis"
    scope="public">
    <ATTR name="tof" type="double" scope="public"/>
    <ATTR name="svd" type="double" scope="public"/>
    <ATTR name="ttt" type="double" scope="public"/>
    <METHOD name="getTof" type="double" scope="public">
    <CODE>return tot;</CODE>
    </METHOD>
    </CLASS>

    here is my xslt

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="text"/>

    <xsl:template match="CLASS">

    import <xsl:value-of select="./@package_name"/>;

    /** This file is generated by
    */
    <xsl:value-of select="./@scope"/> class <xsl:value-of
    select="./@name"/>
    {
    <xsl:for-each select="ATTR">
    <xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
    <xsl:value-of select="./@name"/>;
    </xsl:for-each>

    <xsl:for-each select="METHOD">
    <xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
    <xsl:value-of select="./@name"/>{
    <xsl:value-of select="CODE"/>;
    }
    </xsl:for-each>
    };
    </xsl:template>

    </xsl:stylesheet>

    But here is my output:

    import test;



    /** This file is generated by

    */

    public class TestAnalysis

    {

    publicdoubletof;

    publicdoublesvd;

    publicdoublettt;

    publicdoublegetTof{

    return tot;;

    }



    };

    I miss all the whitespace. How can I fix it?

    Thanks,

    ff
    f, Nov 19, 2003
    #1
    1. Advertising

  2. Replace:

    > <xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
    > <xsl:value-of select="./@name"/>;


    with

    <xsl:value-of select="concat(@scope, ' ', @type, ' ', @name, ';')"/>



    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL




    "f" <> wrote in message
    news:...
    > I am writing a java code generation tool. I use xml and xslt. But I
    > have some problem using xsl:for-each.
    >
    > here is my xml
    > <?xml version = "1.0"?>
    > <CLASS
    > package_name=".test"
    > name="TestAnalysis"
    > scope="public">
    > <ATTR name="tof" type="double" scope="public"/>
    > <ATTR name="svd" type="double" scope="public"/>
    > <ATTR name="ttt" type="double" scope="public"/>
    > <METHOD name="getTof" type="double" scope="public">
    > <CODE>return tot;</CODE>
    > </METHOD>
    > </CLASS>
    >
    > here is my xslt
    >
    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    > <xsl:eek:utput method="text"/>
    >
    > <xsl:template match="CLASS">
    >
    > import <xsl:value-of select="./@package_name"/>;
    >
    > /** This file is generated by
    > */
    > <xsl:value-of select="./@scope"/> class <xsl:value-of
    > select="./@name"/>
    > {
    > <xsl:for-each select="ATTR">
    > <xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
    > <xsl:value-of select="./@name"/>;
    > </xsl:for-each>
    >
    > <xsl:for-each select="METHOD">
    > <xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
    > <xsl:value-of select="./@name"/>{
    > <xsl:value-of select="CODE"/>;
    > }
    > </xsl:for-each>
    > };
    > </xsl:template>
    >
    > </xsl:stylesheet>
    >
    > But here is my output:
    >
    > import test;
    >
    >
    >
    > /** This file is generated by
    >
    > */
    >
    > public class TestAnalysis
    >
    > {
    >
    > publicdoubletof;
    >
    > publicdoublesvd;
    >
    > publicdoublettt;
    >
    > publicdoublegetTof{
    >
    > return tot;;
    >
    > }
    >
    >
    >
    > };
    >
    > I miss all the whitespace. How can I fix it?
    >
    > Thanks,
    >
    > ff
    Dimitre Novatchev, Nov 19, 2003
    #2
    1. Advertising

  3. >>>>> "Dimitre" == Dimitre Novatchev <> writes:

    Dimitre> Replace:
    >> <xsl:value-of select="./@scope"/> <xsl:value-of select="./@type"/>
    >> <xsl:value-of select="./@name"/>;


    Dimitre> with

    Dimitre> <xsl:value-of select="concat(@scope, ' ', @type, ' ', @name,
    Dimitre> ';')"/>



    Yes, I also use xsl to generate java, and use concat alot. I have a couple
    of variables I use lot: indent1, indent2, .. where indent1 is four spaces,
    indent2 eight spaces etc. Then I have variables newline and quote. So almost
    all lines are of form

    <xsl:value-of select="concat($indent2,'System.out.println(',
    $quote,'Value is ',$quote,'+',@name,');',
    $newline)"/>

    --
    Arto V. Viitanen
    University of Tampere, Department of Computer Sciences
    Tampere, Finland http://www.cs.uta.fi/~av/
    Arto V. Viitanen, Nov 20, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oli Filth
    Replies:
    9
    Views:
    3,319
    Uncle Pirate
    Jan 17, 2005
  2. Tjerk Wolterink

    xsl:for-each for each 3 elements problem

    Tjerk Wolterink, Nov 3, 2004, in forum: XML
    Replies:
    3
    Views:
    419
    Tjerk Wolterink
    Nov 3, 2004
  3. Replies:
    1
    Views:
    3,591
    A. Bolmarcich
    May 27, 2005
  4. Replies:
    10
    Views:
    722
    Eric Brunel
    Dec 16, 2008
  5. MRAB
    Replies:
    3
    Views:
    373
Loading...

Share This Page