[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

AW: It's possible to give external parameters in xslt?

Subject: AW: It's possible to give external parameters in xslt?
From: <christof.hoeke@xxxxxxx>
Date: Mon, 29 Mar 2004 17:02:16 +0200
java xsl template
hi,

XSL:
you need to put an xsl:param element in the xsl stylesheet:
	<xsl:param name="p1" select="'default value of not set from java'"/>

this can be used exactly like xsl:variable's:
	<xsl:value-of select="$p1"/>  -> default value of not set from java 

JAVA:
in your java code you just need to call
	transformer2.setParameter(paramname, paramvalue)
so e.g.
	transformer2.setParameter("p1", "hi there")

then the output would be
	<xsl:value-of select="$p1"/>  -> hi there 


i did not run the example, so there might be a typo but this is the way it works. just look into the javax.xml.transform javadoc to find the docs for setParameter.


chris



> -----Urspr|ngliche Nachricht-----
> Von: Roberta Granata [mailto:robgranata@xxxxxxxxxxx]
> Gesendet: Montag, 29. Mdrz 2004 16:54
> An: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Betreff: RE:  It's possible to give external parameters in xslt?
> 
> 
> Hi,
> this is my xml document :
> 
> <?xml version="1.0" ?>
> <ROOT>
>   <Group>Group</Group>
>   <Name>Name</Name>
>   <TitleName>TitleName</TitleName>
>   <SubTitleName>Sub</SubTitleName>
>   <Chapter>
> 
>     <ChapterHead>
>       <ChapterName>ChapterName</ChapterName>
>         <ChapterNameText>ChapterNameTest
>         </ChapterNameText>
>     </ChapterHead>
>     
>     <ChapterLine>
>       <Paragraph>Paragraph</Paragraph>
>       <TextLine>TextLine</TextLine>
>     </ChapterLine>
>   
>   </Chapter>
>   
> </ROOT>
> 
> #------------------
> and this is the xsl :
> 
> <?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="text" encoding="ISO-8859-1"/>
>  <xsl:output media-type="text/plain"/> 
> 
> 
>   <xsl:template match="ROOT">
>     <xsl:apply-templates select="Group | Name |
> TitleName | SubTitleName | Chapter"/>
>   </xsl:template>
> 
>   <xsl:template match="Group">
>     <xsl:value-of select="."/>
>       <xsl:text>
> 
>       </xsl:text>
>   </xsl:template>
> 
>   <xsl:template match="Name">
>     <xsl:value-of select="."/>
>       <xsl:text>
> 
>       </xsl:text>
>   </xsl:template>
> 
>   <xsl:template match="TitleName">
>     <xsl:value-of select="."/>
>       <xsl:text>
>     
>       </xsl:text> 
>   </xsl:template>
> 
>   <xsl:template match="SubTitleName">
>     <xsl:value-of select="."/>
>       <xsl:text>
>     
>       </xsl:text> 
>   </xsl:template>
> 
>   <xsl:template match="Chapter">
>     <xsl:apply-templates select="ChapterHead"/>
>     <xsl:apply-templates select="ChapterLine"/>
>       <xsl:text>
>     
>       </xsl:text> 
>   </xsl:template>
>   
>   <xsl:template match="ChapterHead">
>     <xsl:apply-templates select="ChapterName"/>
>     <xsl:apply-templates select="ChapterNameText"/>
>       <xsl:text>
>     
>       </xsl:text> 
>   </xsl:template>
> 
>   <xsl:template match="ChapterLine">
>     <i><xsl:apply-templates select="Paragraph"/></i>
>       <xsl:text>   </xsl:text> 
>     <xsl:apply-templates select="TextLine"/>
>       <xsl:text>
>     
>       </xsl:text> 
>   </xsl:template>
> 
>   <xsl:template match="ChapterName">
>     <xsl:value-of select="."/>
>   </xsl:template>
> 
>   <xsl:template match="ChapterNameText">
>     <xsl:value-of select="."/>
>       <xsl:text>   </xsl:text> 
>   </xsl:template>
> 
>   <xsl:template match="Paragraph">
>     <xsl:value-of select="."/>
>   </xsl:template>
> 
>   <xsl:template match="TextLine">
>     <xsl:value-of select="."/>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> #-------------------------------------------------
> And i use the java code found in the xalan examples to
> do the transformation :
> 
> 
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
> 
> import javax.xml.transform.Transformer;
> import
> javax.xml.transform.TransformerConfigurationException;
> import javax.xml.transform.TransformerException;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
> 
> /**
>  *  Use the TraX interface to perform a transformation
> in the simplest manner possible
>  *  (3 statements).
>  */
> public class TransformXml2Html
> {
>  public static void main(String[] args)
>     throws TransformerException,
> TransformerConfigurationException, 
>            FileNotFoundException, IOException
>   {  
>  
>  TransformerFactory tFactory =
> TransformerFactory.newInstance();
> 
>  Transformer transformer2 =
> tFactory.newTransformer(new
> StreamSource("GeneralTxt.xsl"));
>  transformer2.transform(new StreamSource("xxx.xml"),
> new StreamResult(new FileOutputStream("xxx.txt")));
> 
>   transformer2.transform(new StreamSource("xxx.xml"),
> new StreamResult(new FileOutputStream("xxx.txt")));
>   System.out.println("************* The result is in 
> xxx.txt *************");
>   }
> }
> 
> #------------------------------------------------
> 
> I tried to insert external parameters in the xsl code
> without success. How i can do that?
> 
> Thanks in advance
> ro   
> 
> 
> 
>  --- cknell@xxxxxxxxxx wrote: > > It's possible to do
> that ?
> >   Yes.
> > > and how?
> >   It depends on how  you are doing the
> > transformation (what XSLT processor are you using?).
> > -- 
> > Charles Knell
> > cknell@xxxxxxxxxx - email
> > 
> > 
> > 
> > -----Original Message-----
> > From:     Roberta Granata <robgranata@xxxxxxxxxxx>
> > Sent:     Mon, 29 Mar 2004 14:53:11 +0100 (BST)
> > To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject:   It's possible to give external
> > parameters in xslt?
> > 
> > Hello all,
> > 
> > I' m new in xslt , and i have a problem when i
> > convert
> > an xml document in a txt document by xslt to give
> > external parameters.It's possible to do that ? and
> > how?
> > 
> > Thanks in advance
> > 
> > ro
> > 
> > 
> > 
> > 
> > 	
> > 	
> > 		
> >
> ___________________________________________________________
> > WIN FREE WORLDWIDE FLIGHTS - nominate a cafe in the
> > Yahoo! Mail Internet Cafe Awards 
> > www.yahoo.co.uk/internetcafes 
> >  
> 
> 
> 	
> 	
> 		
> ___________________________________________________________
> WIN FREE WORLDWIDE FLIGHTS - nominate a cafe in the Yahoo! 
> Mail Internet Cafe Awards  www.yahoo.co.uk/internetcafes 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.