xsl-list
[Top] [All Lists]

Re: Pass variables through URL

2004-10-19 01:32:34
Jen Jiang wrote:

Here's the xslt file that has the url:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:import href="cascademenu_member.xsl"/>
        <xsl:import href="footer.xsl"/>
        <xsl:import href="menubarh.xsl"/>
        <xsl:import href="menubarh_member.xsl"/>
        <xsl:import href="header.xsl"/>
        <xsl:output method="text/html"
Hi Jen,

xsl:output method should be either "text", "xml" or "html". Saxon refuses method="text/html", but with method="html" (and without the imports) produces the desired result. I think Werner is right, maybe you're changing the context somewhere, and using "/ROOT" might fix it. But...

<div align="center">
        <xsl:for-each select="ROOT">
                <xsl:variable name="age1">
                        <xsl:value-of select="AGE1"/>
                </xsl:variable>
                THIS IS AGE1:<xsl:value-of select="$age1"/>
                <xsl:variable name="age2">
                        <xsl:value-of select="AGE2"/>
                </xsl:variable>
                <xsl:variable name="age3">
                        <xsl:value-of select="AGE3"/>
                </xsl:variable>
                <xsl:variable name="age4">
                        <xsl:value-of select="AGE4"/>
                </xsl:variable>
                <xsl:variable name="age5">
                        <xsl:value-of select="AGE5"/>
                </xsl:variable>
                <xsl:variable name="age6">
                        <xsl:value-of select="AGE6"/>
                </xsl:variable>
                <xsl:variable name="age7">
                        <xsl:value-of select="AGE7"/>
                </xsl:variable>
                <xsl:variable name="age8">
                        <xsl:value-of select="AGE8"/>
                </xsl:variable>
                <xsl:element name='img'>
                        <xsl:attribute name='src'>
                                <xsl:text>./php/chart_age.php?age1=</xsl:text>
                                <xsl:value-of select='$age1'/>
                                <xsl:text>&amp;age2=</xsl:text>
                                <xsl:value-of select='$age2'/>
                                <xsl:text>&amp;age3=</xsl:text>
                                <xsl:value-of select='$age3'/>
                                <xsl:text>&amp;age4=</xsl:text>
                                <xsl:value-of select='$age4'/>
                                <xsl:text>&amp;age5=</xsl:text>
                                <xsl:value-of select='$age5'/>
                                <xsl:text>&amp;age6=</xsl:text>
                                <xsl:value-of select='$age6'/>
                                <xsl:text>&amp;age7=</xsl:text>
                                <xsl:value-of select='$age7'/>
                                <xsl:text>&amp;age8=</xsl:text>
                                <xsl:value-of select='$age8'/>
                        </xsl:attribute>
                </xsl:element>                    
        </xsl:for-each>
</div>

And the XML file that has the values of age1-age8.

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
        <AGE1>30</AGE1>
        <AGE2>10</AGE2>
        <AGE3>30</AGE3>
        <AGE4>10</AGE4>
        <AGE5>20</AGE5>
        <AGE6>0</AGE6>
        <AGE7>0</AGE7>
        <AGE8>0</AGE8>
</ROOT>


Why would you make it so complicated? Why not pass the values directly, instead of first collecting them into 8 variables:

       <xsl:for-each select="/ROOT">
           <img>
               <xsl:attribute name='src'>
                   <xsl:text>./php/chart_age.php?age1=</xsl:text>
                   <xsl:value-of select='AGE1'/>
                   <xsl:text>&amp;age2=</xsl:text>
                   <xsl:value-of select='AGE2'/>
                   <xsl:text>&amp;age3=</xsl:text>
                   <xsl:value-of select='AGE3'/>
                   <xsl:text>&amp;age4=</xsl:text>
                   <xsl:value-of select='AGE4'/>
                   <xsl:text>&amp;age5=</xsl:text>
                   <xsl:value-of select='AGE5'/>
                   <xsl:text>&amp;age6=</xsl:text>
                   <xsl:value-of select='AGE6'/>
                   <xsl:text>&amp;age7=</xsl:text>
                   <xsl:value-of select='AGE7'/>
                   <xsl:text>&amp;age8=</xsl:text>
                   <xsl:value-of select='AGE8'/>
               </xsl:attribute>
           </img>
       </xsl:for-each>

Or even iterate through the AGE elements to build up the url:

       <xsl:for-each select="/ROOT">
           <img>
               <xsl:attribute name='src'>
                   <xsl:text>./php/chart_age.php?</xsl:text>
                   <xsl:for-each select="*">
                       <xsl:if test="position() > 1">&amp;</xsl:if>
<xsl:value-of select="translate(name(),$upper,$lower)"/>
                       <xsl:text>=</xsl:text>
                       <xsl:value-of select="."/>
                   </xsl:for-each>
               </xsl:attribute>
           </img>
       </xsl:for-each>

Here you'll need the upper and lower variables:
   <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
   <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
(mind the double quotes in the select attribute!)

Best regards,
Anton


<Prev in Thread] Current Thread [Next in Thread>