Passing Parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compGam
    New Member
    • Nov 2008
    • 1

    Passing Parameters

    Hello everyone,

    I am relatively new to XML, and I'm having trouble multiplying parameters that I passed in from an XML document using using XSLT.

    Here is my XML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="Teacher.x sl"?>
    <pay>
    <sub1>30</sub1>
    <hourlyRate>15. 75</hourlyRate>
    </pay>


    Here is my XSLT file:

    <?xml version="1.0" ?>
    <xsl:styleshe et version="1.0" xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:template match="pay">
    <html>
    <body>
    <xsl:apply-templates select="sub1"/>
    <xsl:apply-templates select="hourlyR ate"/>
    <xsl:value-of select="$onevar iable*$twovaria ble"/>
    </body>
    </html>
    </xsl:template>
    <xsl:template match="sub1">
    <xsl:param name="onevariab le"/>
    <br/><xsl:value-of select = "$onevariab le"/>
    <br />Hours: <xsl:value-of select="."/>


    </xsl:template>
    <xsl:template match="hourlyRa te">
    <xsl:param name="twovariab le"/>
    <br/><xsl:value-of select="$twovar iable"/>
    <br />Pay Rate: <xsl:value-of select="."/>



    </xsl:template>
    </xsl:stylesheet>



    Basically, I have to to multiply onevariable and twovariable with the "$". I don't where in the document to declare it.


    Thanks in advance for anyone who can help me with this problem.

    (Sorry if the thread is long.)
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Hi compGam,

    in your case use the self::node() wildcard (.).
    Code:
    <xsl:param name="onevariable" select="."/>
    you could also define it just before the computation:
    Code:
    <xsl:variable name="onevariable" select="//sub1"/>
    you could even use:
    Code:
    <xsl:value-of select="number(//sub1/text())+number(//hourlyRate/text())"/>
    more on parameters: XML.com: Setting and Using Variables and Parameters

    and one more thing:

    For the benefit of our experts and yourself, it is a posting guidelines that all users use [code] tags when posting code. This makes the code easier to read and, in turn, helps our experts answer your questions.

    An easy way to do this is to highlight the code in the textarea and then hit the '#' button at the top of the textarea.

    Please read the Posting Guidelines so you're more familiar with how things work.

    regards

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      not sure if you're doing one thing or the other...

      Where are you declaring these variables?
      Don't forget when you declare a parameter in a template, it's only works inside that template. You can't use it when it comes back.

      Instead of
      <xsl:value-of select="$onevar iable*$twovaria ble"/>
      try:
      <xsl:value-of select="sub1 * hourlyRate"/>

      Comment

      Working...