netuh Posted November 4, 2006 Share Posted November 4, 2006 Hi,Its me again, Someone know how i pass parameters to transformation?for example, the code in Java for transfomation: transformer = tFactory.newTransformer( new StreamSource("foo.xls")); transformer.transform( new StreamSource("foo.xml"), new StreamTarget("moo.xml")); and te transformation <?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="xml" indent="yes"/><xsl:template match="/"><foo> <xsl:for-each select="/thing"> <xsl:if test="name = 'moo' "> <moo/> </xsl:if> </xsl:for-each></foo></xsl:template></xsl:stylesheet> Well, on the contrary compare if name = 'moo', i need passe to transfomation the name for compare.Thanks again... Link to comment Share on other sites More sharing options...
boen_robot Posted November 6, 2006 Share Posted November 6, 2006 Well, obviously, you need to create the parameter to begin with. For example, if you want to have a $thing to compare against, with a default value of "moo", you can define it like this: <?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="xml" indent="yes"/><xsl:param name="thing" select="'moo'"/><xsl:template match="/"><foo> <xsl:for-each select="/thing[name = $thing]"> <moo/> </xsl:for-each></foo></xsl:template></xsl:stylesheet> And the way to pass params varies depending on the language used to execute the transformation. For JavaScript, all I can offer you is the function in this post which is the closest thing you can get to. That JS needs to be executed from within the XSLT. With adjustments, you might be able to use it from somewhere else. Link to comment Share on other sites More sharing options...
netuh Posted November 6, 2006 Author Share Posted November 6, 2006 Thanks,Sorry, i already knew that I would have to create parameters. But i forgot insert in example. I was study a Java processor, Xalan. And i discovered the method addParameters(String expression).Thanks for the help again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now