Forum Moderators: open
I am using PHP's xslt_process to merge and display an XML and XSL document.
My XML is like...
<page number="1">
<content>this is page 1</content>
</page>
<page number="2">
<content>this is page 2</content>
</page>
<page number="3">
<content>this is page 3</content>
</page>
I want to pass a parameter from PHP to XSL to determine which page gets displayed.
I know how to pass a parameter and display it like this...
<xsl:param name="page" />
<xsl:value-of select="$page" />
But how do I use the parameter within an if statement? I'm looking for something like..
<xsl:if test="$page = 1">
(but that doesn't work!)
Any help or pointers appreciated - many thanks.
<xsl:variable name="internalPageVar" select="inwardPageVar"/>
Then use
<xsl:choose>
<xsl:when test="$internalPageVar = '1'">
</xsl:when>
<xsl:when ...>
</xsl:when>
<xsl:otherwise>
<xsl:otherwise>
</xsl:choose>
Might work remember that XSL is useless with creating and doing things on the fly - but I am not fully sure of your intention.
-George
I haven't yet tried the code you suggest but what is "inwardPageVar" and "internalPageVar"? Are they names you have made up or names that XSL will understand. (Google doesn't know them!).
Thanks.
I have tried this but no luck. I must admit at this point, that I have just realised the code I provided in my first post does work...
<xsl:if test="$page = 1">
do some tranformation
</xsl:if>
But it doesn't solve my problem because it doesn't reference the attribute of my XML page tag, <page number="1">
I guess I'm just trying to run before I can walk and will need to do another few weeks of reading before I have the skills to target an attribute in this way.
Not too sure on params but where you assign your local variable it should reference the xml something like:
<xsl:variable name="page" select="page/@number"/>
I am using xsl:variables as I am more sure of them ;-)
number is at the root of the page element and should be reference with the @ sign
Lets know if that assists any
-George
I have been using something similar to
<xsl:choose>
<xsl:when test="$myvar='a'">
do something
</xsl:when>
<xsl:when test="myvar='b'">
do something else
</xsl:when>
</xsl:choose>
don't know it it will work any better/with parameters. I know I used params at some point - but it was some time ago and i forget now.
-- oops - just spotted the original reply, *shame*