Subject: Re: [xsl] passing parameters to XSL,what if no value in some cases From: Nic Gibson <nicg@xxxxxxxxxx> Date: Mon, 9 Mar 2009 11:05:50 +0000 |
2009/3/7 himanshu padmanabhi <himanshu.padmanabhi@xxxxxxxxx>: > Thank you all.If I passed arguments using hash %params.How to access > them in XSL file, > I tried this,but got error. > B <xsl:param name="args" select="$params{$args}" /> > B <xsl:param name="val" select="$params{$val}" /> > B <xsl:param name="newl" select="$params{$new}" /> > > What are the advantages of passing it using hash? > Using XML::LibXSLT, you are (obviously) using perl parameter passing conventions. The transform method takes a series of pairs as parameters (each pair being name followed by correctly quoted value). Generally, in perl, one is always passing an array to subroutine. Subroutine parameters are treated as an array from the point of view of the called routine. When you pass a hash to a subroutine perl flattens that hash out to an array of names and values exactly as above. As you can see from the docs, the transform method expects a hash argument (I was looking at http://search.cpan.org/~pajas/XML-LibXSLT-1.68/LibXSLT.pm). So, your approach of passing names and values and mine of passing hashes are functionally identical. Now, what is not made clear in the documentation is that, for each key in the hash of attributes, an xslt param with the same name as the key is instantiated. So, you simply need: <xsl:param name="args" select="mydefault1" /> <xsl:param name="val" select="mydefault2" /> <xsl:param name="newl" select="mydefault3" /> where mydefault[1-3] are your sensible defaults should the calling perl code not provide you with a value. hth nic -- Nic Gibson Director, Corbas Consulting Editorial and Technical Consultancy http://www.corbas.co.uk/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] passing parameters to XSL, Florent Georges | Thread | [xsl] Removal of similar but differ, Mark Wilson |
[xsl] Processing related complex ob, Mark Wilson | Date | [xsl] question on default namespace, Torsten Schassan |
Month |