Subject: Re: [xsl] roblems with passing variables from PHP to XSLT From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 6 Jun 2006 14:00:06 +0100 |
You want to make code a parameter to the stylesheet <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:php="http://php.net/xsl"> <xsl:output method="html"/> <xsl:param name="code" select="'PEN'"/> then you can change the value from its default 'PEN' when you call XSLT (the details depend on the API you are using, sorry I can't help with php, but google or the docs will no doubt say how to initialise a stylesheet parameter, once you have one declared). then in an ideal world you would just replace 'PEN' in your code with $code and it would all work: <xsl:template match="IATA[@code=$code]/ProductItem">.....</xsl:template> <xsl:template match="IATA[@code!=$code]/ProductItem"></xsl:template> Beware that those two tests are not mutually exclusive, you probably want <xsl:template match="IATA[not(@code=$code)]/ProductItem"></xsl:template> for the second one However unfortuantely there is a restriction in XSLT1 (which you are using) that you can not use variables in match patterns. In XSLT2 this restriction is gone, but in XSLT1 you have to re-write it as <xsl:template match="IATA/ProductItem"> <xsl:if test="@code=$code">.....</xsl:if></xsl:template> </xsl:template> <xsl:value-of select="ProductItemDetail/ProductText" disable-output-escaping="yes"/></p> Don't use disable-output-escaping unless you are sure you really need it (and even then don't use it unless your really can't avoid it). David ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] roblems with passing vari, David Carlisle | Thread | [xsl] XSLT 2.0: Reasons for mode="#, Dimitre Novatchev |
Re: [xsl] XSLT 2.0: Reasons for mod, Rene Ladan | Date | Re: [xsl] roblems with passing vari, David Carlisle |
Month |