You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Anne-Claire Trommenschlager <An...@steria.ch> on 2001/05/02 11:34:05 UTC
Creation of stylesheets with some parameters
Hi Dave,
You give me an answer few ago about how to create stylesheet in a dynamic
way, but I didn't understand what I have to do. I am french and sometimes my
english is so bad. I use Xalan-J-2.0.1 and jdk 1.3.
> Hi Anne-Claire,
> You can use xsl:element to generate elements in the result tree. The name
> attribute of xsl:element is an attribute value template (AVT), so the
value
> can be any XPath expression. That means you can generate element names
> based on information in the source tree, or the value of a variable. If
> you are writing custom code, the value of a variable can be a parameter to
> the stylesheet, which you can set before you call the transform. So, you
> should be able to generate a stylesheet which will match the element names
> in your documents.
> Dave
So I propose to take an example to what I want to do and maybe you can give
me a small example of JAVA code such I can begin to create one stylesheet. I
am lost.
My xml file is like :
<?xml version="1.0" encoding="ISO-8859-1"?>
<PRODUITS>
<PRODUIT CODE="117885" CAT="TV">
<NOM>TV 16/9</NOM>
<REF>ASG 1609</REF>
<MARQUE>XML TV</MARQUE>
<PRIX>8750</PRIX>
</PRODUIT>
<PRODUIT CODE="118553" CAT="TV">
<NOM>TV 51</NOM>
<REF>ASG 5118</REF>
<MARQUE>XML TV1</MARQUE>
<PRIX>1200</PRIX>
</PRODUIT>
</PRODUITS>
And I want to create I don't know how an XSL file :
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<TABLE STYLE="width:100%">
<TR STYLE="background='lightgrey'">
<TD>Types of products</TD>
<TD>Names</TD>
<TD>Marks</TD>
<TD>References</TD>
<TD>Prices</TD>
</TR>
<xsl:apply-templates/>
</TABLE>
</xsl:template>
<xsl:template match="PRODUITS">
<xsl:for-each select="PRODUIT">
<xsl:element name="TR">
<xsl:element name="TD">
<xsl:choose>
<xsl:when test="self::node()[@CAT='TV']">Television</xsl:when>
<xsl:otherwise>Produit inconnu</xsl:otherwise>
</xsl:choose>
</xsl:element>
<xsl:element name="TD">
<xsl:value-of select="NOM"/>
</xsl:element>
<xsl:element name="TD">
<xsl:value-of select="MARQUE"/>
</xsl:element>
<xsl:element name="TD">
<xsl:value-of select="REF"/>
</xsl:element>
<xsl:element name="TD">
<xsl:value-of select="PRIX"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I don't know what it is possible to do. In theory I suppose you can fixe a
structure. I always will have a table in HTML tree. The only differences are
the name of columns and the values of each select. I think I will have this
things in parameters or something like that.
Please help me
Thanks
Anne-Claire