ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: XSLT question (passing parameters)
by Lars Haugseth other posts by this author
Nov 20 2005 12:32PM messages near this date
view in the new Beta List Site
XSLT question (passing parameters) | Re: XSLT question (passing parameters)
& XSLT On Saturday 19 November 2005 13:27, David Craig wrote:
>  Hello all,
> 
>  I'm having a problem with passing in external parameters... I've tried
>  several transformation engines (komodo built in, XML::LibXSLT) to no
>  avail, so I think I'm making a mistake in the code. A really simple
>  example is this:
> 
>  <?xml version="1.0" encoding="UTF-8"?>
>  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  version="1.0">
>  <xsl:param name="x"/>

<xsl:param>  is only for getting parameters in a template called
with <xsl:with-param>  arguments.

>  <xsl:template match="/">
>              <xsl:text>|</xsl:text><xsl:value-of select="$x"
>  /><xsl:text>|</xsl:text>
>      </xsl:template>
>  </xsl:stylesheet>
> 
>  I would expect to get "|valueofx|" but instead I get "||"
> 
>  Am I being stupid?
> 
>  Thanks for your help!

If you're trying to pass parameters from your Perl code to the stylesheet, try 
something like this:

Within the Perl code:

  my $xslt = XML::LibXSLT-> new() or
    die "Can't create XML::LibXSLT object.";

  my $stylesheet = $xslt-> parse_stylesheet_file('stylesheet.xsl') or
    die "Can't parse stylesheet.";

  my @xsltParams = ();
  push @xsltParams, ('foo', 'some-value');
  push @xsltParams, ('bar', 'some-other-value');
  my $result = $stylesheet-> transform_file('document.xml', @xsltParams);

Within the stylesheet:

  <xsl:text> Value of foo is </xsl:text><xsl:value-of select="$foo"/>
  <xsl:text> Value of bar is </xsl:text><xsl:value-of select="$bar"/>

Regards,
-- 
Lars Haugseth
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
David Craig
Lars Haugseth
A. Pagaltzis
Stephane Roux
A. Pagaltzis

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved