how to apply two XSL transformations to one XML file

F

Franck Perrin

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top