how to apply two XSL transformations to one XML file

Discussion in 'XML' started by Franck Perrin, Jul 14, 2003.

  1. I'd like to know if there is a way to apply to successive XSL
    transformations on one XML file.

    I got this XML file :
    <page Action="N047">
    <data defaultName="c0dos010" Type="String" CustomName=""/>
    <data defaultName="clxc0233" Type="String" CustomName="EndDate"/>
    </page>

    I want to generate java code like this :

    ******************************************************************************
    package cnaf.param ;
    import cnaf.framework.cnafdate.*;
    import cnaf.framework.services.*;

    public class N047
    {
    private static final String NCC = N047.class.getName();
    private String c0dos010;
    private String EndDate;

    public N047() //constructeur
    {}
    public void setc0dos010 (String value)
    {c0dos010=value;}
    public String getc0dos010()
    {return c0dos010;}
    public void setEndDate (String value)
    {EndDate=value;}
    public String getEndDate()
    {return EndDate;}
    ******************************************************************************

    I wrote this XSL code :

    ------------------------------------------------------------------------------
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xslscr="http://www.w3.org/TR/WD-xsl" version="1.0">
    <xsl:eek:utput method="text"/>
    <xsl:template match="page">


    package cnaf.param ;
    import cnaf.framework.cnafdate.*;
    import cnaf.framework.services.*;

    public class <xsl:value-of select="@Action"/>
    {

    private static final String NCC = <xsl:value-of
    select="@Action"/>.class.getName();
    <xsl:for-each select="data">
    <xsl:variable name = "PropName">
    <xsl:choose>
    <xsl:when test="@CustomName!=''">
    <xsl:value-of select="@CustomName"/>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:value-of select="@defaultName"/>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name = "type">
    <xsl:choose>
    <xsl:when test="@Type != ''">
    <xsl:value-of select="@Type"/>
    </xsl:when>
    <xsl:eek:therwise>String</xsl:eek:therwise>
    </xsl:choose>
    </xsl:variable>
    private <xsl:value-of select="$type" /><xsl:text> </xsl:text>
    <xsl:value-of select="$PropName" />;
    </xsl:for-each>

    public <xsl:value-of select="@Action" />() //constructeur
    {
    }
    <xsl:for-each select="data">

    <xsl:variable name = "PropName">
    <xsl:choose>
    <xsl:when test="@CustomName!=''">
    <xsl:value-of select="@CustomName"/>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:value-of select="@defaultName"/>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:variable>
    <xsl:variable name = "type">
    <xsl:choose>
    <xsl:when test="@Type != ''">
    <xsl:value-of select="@Type"/>
    </xsl:when>
    <xsl:eek:therwise>String</xsl:eek:therwise>
    </xsl:choose>
    </xsl:variable>

    public void set<xsl:value-of select="$PropName" /> (<xsl:value-of
    select="$type" /> value)
    {<xsl:value-of select="$PropName" />=value;}

    public <xsl:value-of select="$type" /> get<xsl:value-of
    select="$PropName" />()
    {return <xsl:value-of select="$PropName" />;}
    </xsl:for-each>
    }
    </xsl:template>
    </xsl:stylesheet>
    ------------------------------------------------------------------------------

    But definition of variables "PropName" and "type" are declared twice.
    If I could produce a intermediate XML file like this :
    <page Action="N047">
    <data PropName="c0dos010" Type="String"/>
    <data PropName="EndDate" Type="String"/>
    </page>
    I wouldn't be oblige to declare variables twice because I would have
    controled the value of the attributes as I generate the temporary XML
    file.

    The problem is that I can't find how to do what I want.
    Is there anybody who can help me?
    Franck Perrin, Jul 14, 2003
    #1
    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. George Durzi

    Performance of Xsl Transformations

    George Durzi, Dec 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    3,509
    George Durzi
    Dec 31, 2003
  2. Sparko
    Replies:
    0
    Views:
    402
    Sparko
    Jul 9, 2004
  3. Vijay singh
    Replies:
    1
    Views:
    428
    Martin Honnen
    Nov 4, 2004
  4. Szymon Nieradka

    DocBook custom XSL transformations

    Szymon Nieradka, May 11, 2006, in forum: XML
    Replies:
    4
    Views:
    621
    Peter Flynn
    May 13, 2006
  5. Geico Caveman
    Replies:
    0
    Views:
    520
    Geico Caveman
    Oct 2, 2008
Loading...

Share This Page