XSL: parameter checking

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sharon

    XSL: parameter checking

    Hi,
    Is it possible to check parameters against other parameters, as in:

    <xsl:variable name="tableData ">
    <xsl:apply-templates
    select="general/data/rows/row/fvalues[$FIELD1=$FILTER 1][$FIELD2=$FILTER 2]"
    mode="tableData " />
    </xsl:variable>

    (The parts I'm referring to are in capitals). Because this gives me no
    output where I'm expecting 6 node elements. Is this because it's not
    possible to use parameters this way or is it just me making some other
    mistake in my Xpath? I hope the second is true so I don't have to come
    up with another solution... Thanks! Sharon
  • Janwillem Borleffs

    #2
    Re: parameter checking

    Sharon wrote:[color=blue]
    > Hi,
    > Is it possible to check parameters against other parameters, as in:
    >
    > <xsl:variable name="tableData ">
    > <xsl:apply-templates
    > select="general/data/rows/row/fvalues[$FIELD1=$FILTER 1][$FIELD2=$FILTER 2]"
    > mode="tableData " />
    > </xsl:variable>
    >[/color]

    select="general/data/rows/row/fvalues[$FIELD1=$FILTER 1 and
    $FIELD2=$FILTER 2]"


    JW



    Comment

    • Ben Edgington

      #3
      Re: XSL: parameter checking

      esdeees@hotmail .com (Sharon) writes:[color=blue]
      > Is it possible to check parameters against other parameters, as in:
      >
      > <xsl:variable name="tableData ">
      > <xsl:apply-templates
      > select="general/data/rows/row/fvalues[$FIELD1=$FILTER 1][$FIELD2=$FILTER 2]"
      > mode="tableData " />
      > </xsl:variable>
      >
      > (The parts I'm referring to are in capitals). Because this gives me no
      > output where I'm expecting 6 node elements. Is this because it's not
      > possible to use parameters this way or is it just me making some other
      > mistake in my Xpath? I hope the second is true so I don't have to come
      > up with another solution... Thanks! Sharon[/color]

      Give the expression

      "general/data/rows/row/fvalues[$FIELD1=$FILTER 1 and $FIELD2=$FILTER 2]"

      a try and see if it helps. If not then post again with a bigger
      example (eg. some XML input and an idea of the output you want).

      Ben

      --
      Ben Edgington
      Mail to the address above is discarded.
      Mail to ben at that address might be read.

      Comment

      • Sharon Steringa

        #4
        Re: XSL: parameter checking

        Thanks, you guys, but that wasn't the problem. My XSL works fine when I
        change the line to:
        select="general/data/rows/row/fvalues[fclient=$filter 1][fcity=$filter2]"
        mode="tableData "[color=blue]
        > that is when I change the first parameter into a specific node. But[/color]
        that's exactly what I'm trying to avoid: I want to create a filter that
        is not predefined and takes table values that are selected by the user
        as its parameters(colu mn name would be $field and filtervalue would be
        $filter). The parameter $field could then take any of the existing
        column names (such as fclient, fcity etc.) as its value and the
        parameter $filter would contain the value to be filtered on. Obviously
        it can't be done this way, can anyone tell me how I might work around
        this problem? Thanks! Sharon

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Ben Edgington

          #5
          Re: XSL: parameter checking

          Sharon Steringa <esdeees@hotmai l.com> writes:[color=blue]
          > Thanks, you guys, but that wasn't the problem. My XSL works fine when I
          > change the line to:
          > select="general/data/rows/row/fvalues[fclient=$filter 1][fcity=$filter2]"
          > mode="tableData "[color=green]
          > > that is when I change the first parameter into a specific node. But[/color]
          > that's exactly what I'm trying to avoid: I want to create a filter that
          > is not predefined and takes table values that are selected by the user
          > as its parameters(colu mn name would be $field and filtervalue would be
          > $filter). The parameter $field could then take any of the existing
          > column names (such as fclient, fcity etc.) as its value and the
          > parameter $filter would contain the value to be filtered on. Obviously
          > it can't be done this way, can anyone tell me how I might work around
          > this problem? Thanks! Sharon[/color]

          It's kind of hard to understand the problem without the example code I
          suggested you post, so it's no surprise that the answers are off-beam.

          Anyway, I hope I've managed to decipher what you want from the
          somewhat obscure description above. Try this:

          select="general/data/rows/row/fvalues/
          *[name()=$field and node()=$filter1]/../
          *[name()=$filter and node()=$filter2]/.."

          [Note, I've split the line to avoid wrapping: just join it all up]

          Ben

          --
          Ben Edgington
          Mail to the address above is discarded.
          Mail to ben at that address might be read.

          Comment

          • Sharon Steringa

            #6
            Re: XSL: parameter checking

            Hmmm, that's a good lesson for me because I was trying to be as clear as
            possible about my problem and thought I had succeeded :-)...Maybe it's
            time I improve my communication skills. Anyway, the reason I was
            reluctant to post my XML and XSL is because when I did that before,
            nobody answered so I thought: "Maybe it scares people...So if I want
            answers I will have to ask small questions and not provide too much code
            at once." Here's my XML anyway:

            <?xml version="1.0" encoding="utf-8" ?>
            <general>
            <data>
            <header></header>
            <global>
            <orderby />
            <created />
            </global>
            <cols>
            <fclient caption="Client " type="number" visible="True" />
            <fid caption="Sleute lveld" type="number" visible="True" />
            <fusername caption="Userna me" type="number" visible="True"/>
            <fname caption="Naam" type="text" visible="True" />
            <fcity caption="Woonpl aats" type="text" visible="True" />
            <factive caption="Active " type="text" visible="False" />
            <fdebno caption="Debite urnr" type="number" visible="True" />
            <fpassword caption="passwo rd" type="text" visible="False" />
            </cols>
            <rows>
            <row>
            <id value="32" />
            <fvalues>
            <fclient>1</fclient>
            <fid>13</fid>
            <fusername>Piet je</fusername>
            <fname>Pieter s Autotransport B.V.</fname>
            <fcity>Meppel </fcity>
            <factive>True </factive>
            <fdebno>5</fdebno>
            <flanguage>NL </flanguage>
            <fpassword>Flup </fpassword>
            </fvalues>
            </row>
            <row>
            <id value="43" />
            <fvalues>
            <fclient>2</fclient>
            <fid>43</fid>
            <fusername>Will ie</fusername>
            <fname>Willie Bruining</fname>
            <fcity>Blijha m</fcity>
            <factive>True </factive>
            <fdebno>9</fdebno>
            <flanguage>NL </flanguage>
            <fpassword>Kwik </fpassword>
            </fvalues>
            </row>
            <row>
            <id value="21" />
            <fvalues>
            <fclient>3</fclient>
            <fid>83</fid>
            <fusername>Bert je</fusername>
            <fname>Bertje Autotransport B.V.</fname>
            <fcity>Meppel </fcity>
            <factive>True </factive>
            <fdebno>9</fdebno>
            <flanguage>NL </flanguage>
            <fpassword>Kwek </fpassword>
            </fvalues>
            </row>
            <row>
            <id value="64" />
            <fvalues>
            <fclient>0</fclient>
            <fid>73</fid>
            <fusername>Bill ie</fusername>
            <fname>Billie Bruining</fname>
            <fcity>Billieha m</fcity>
            <factive>True </factive>
            <fdebno>3</fdebno>
            <flanguage>NL </flanguage>
            <fpassword>Kwak </fpassword>
            </fvalues>
            </row>
            <row>
            <id value="25" />
            <fvalues>
            <fclient>5</fclient>
            <fid>23</fid>
            <fusername>Piet je</fusername>
            <fname>Bob Autotransport B.V.</fname>
            <fcity>Zaanda m</fcity>
            <factive>True </factive>
            <fdebno>9</fdebno>
            <flanguage>NL </flanguage>
            <fpassword>Kwuk </fpassword>
            </fvalues>
            </row>
            <row>
            <id value="68" />
            <fvalues>
            <fclient>4</fclient>
            <fid>10</fid>
            <fusername>Sjoe rd</fusername>
            <fname>Sjoerd de Vries</fname>
            <fcity>Billieha m</fcity>
            <factive>True </factive>
            <fdebno>5</fdebno>
            <flanguage>NL </flanguage>
            <fpassword>Kwok </fpassword>
            </fvalues>
            </row>
            </rows>
            </data>
            <footer></footer>
            </general>

            And here's the XSL (based on an example by RDC Pro):

            <?xml version="1.0" encoding="UTF-8"?>
            <xsl:styleshe et version="1.0"
            xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
            xmlns:msxsl="ur n:schemas-microsoft-com:xslt"
            xmlns:dates="ur n:rdcpro-com:dates">
            <xsl:output method="html" encoding="UTF-8"/>
            <xsl:param name="username" select="general/data/rows/row"/>
            <xsl:param name="field1" select="'fclien t'"/>
            <xsl:param name="filter1" select="$userna me/fvalues/fclient"/>
            <xsl:param name="field2" select="'fcity' "/>
            <xsl:param name="filter2" select="$userna me/fvalues/fcity"/>
            <xsl:param name="direction ">ascending </xsl:param>
            <xsl:param name="sortBy">f username</xsl:param>
            <xsl:variable name="tableData ">
            <xsl:apply-templates
            select="general/data/rows/row/fvalues[name()=$field1 and
            node()=$filter1][name()=$field2 and node()=$filter2] " mode="tableData "
            />
            </xsl:variable>
            <xsl:template match="general/data">
            <div align="left">
            <div class="content" align="right" style="padding-bottom:4px;">
            Sort Direction:
            <xsl:value-of select="$direct ion"/><br/>
            Sort Column:
            <xsl:value-of select="$sortBy "/>
            </div>
            <table border="1" class="results" align="center" cellpadding="5"
            cellspacing="0" >
            <tr>
            <th>
            <a class="clickanc hor" onclick="render Data('fclient') ;">
            <xsl:value-of select="cols/fclient/@caption"/>
            </a>
            </th>
            <th>
            <a class="clickanc hor" onclick="render Data('fid');">
            <xsl:value-of select="cols/fid/@caption"/>
            </a>
            </th>
            <th>
            <a class="clickanc hor" onclick="render Data('fusername ');">
            <xsl:value-of select="cols/fusername/@caption"/>
            </a>
            </th>
            <th>
            <a class="clickanc hor" onclick="render Data('fname');" >
            <xsl:value-of select="cols/fname/@caption"/>
            </a>
            </th>
            <th>
            <a class="clickanc hor" onclick="render Data('fcity');" >
            <xsl:value-of select="cols/fcity/@caption"/>
            </a>
            </th>
            <th>
            <a class="clickanc hor" onclick="render Data('fdebno'); ">
            <xsl:value-of select="cols/fdebno/@caption"/>
            </a>
            </th>
            </tr>
            <xsl:apply-templates select="msxsl:n ode-set($tableData)/fvalues">
            <xsl:sort select="*[name()=$sortBy]" order="{$direct ion}"/>
            </xsl:apply-templates>
            </table>
            </div>
            </xsl:template>
            <xsl:template match="fvalues" >
            <tr>
            <xsl:for-each select="*">
            <td>
            <xsl:value-of select="."/>
            </td>
            </xsl:for-each>
            </tr>
            </xsl:template>
            <xsl:template match="fvalues" mode="tableData ">
            <xsl:copy>
            <xsl:for-each select="*">
            <xsl:if
            test="/general/data/cols/*[name()=name(cur rent())]/@visible='True' ">
            <xsl:copy-of select="."/>
            </xsl:if>
            </xsl:for-each>
            </xsl:copy>
            </xsl:template>
            </xsl:stylesheet>

            Now I want the data to display properly, just like it does with the
            select statement of the apply-templates in the variable that I mentioned
            in my last post. I filled in what I thought you meant in my XSL but it
            still won't show any data, maybe you meant something else. Anyway thanks
            a lot for your comments, hope you can help me some more with this
            example code. Thanks! Sharon


            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            • Ben Edgington

              #7
              Re: XSL: parameter checking

              Sharon Steringa <esdeees@hotmai l.com> writes:[color=blue]
              > Hmmm, that's a good lesson for me because I was trying to be as clear as
              > possible about my problem and thought I had succeeded :-)...Maybe it's
              > time I improve my communication skills. Anyway, the reason I was
              > reluctant to post my XML and XSL is because when I did that before,
              > nobody answered so I thought: "Maybe it scares people...So if I want
              > answers I will have to ask small questions and not provide too much code
              > at once." Here's my XML anyway:[/color]

              It's much quicker for anyone trying to work on a problem if an example
              is given - preferably a small abstract that encapsulates the problem -
              including the code, input data and the output you expect.

              Text descriptions of problems are rarely easy to follow. A snippet of
              code is so much clearer.
              [color=blue]
              > Now I want the data to display properly, just like it does with the
              > select statement of the apply-templates in the variable that I mentioned
              > in my last post. I filled in what I thought you meant in my XSL but it
              > still won't show any data, maybe you meant something else. Anyway thanks
              > a lot for your comments, hope you can help me some more with this
              > example code. Thanks! Sharon[/color]

              Your XSL has the following XPat expression[color=blue]
              > general/data/rows/row/fvalues[name()=$field1 and
              > node()=$filter1][name()=$field2 and node()=$filter2][/color]

              which bears only a passing resemblence to what I wrote. If you do
              actually put in what I wrote it works fine. The dots and stars
              make all the difference:

              <xsl:apply-templates
              select="general/data/rows/row/fvalues/*[name()=$field1 and
              node()=$filter1]/../*[name()=$field2 and node()=$filter2]/.."
              mode="tableData "
              />

              With your data and corrected template you get all the output
              (because your parameter statements for filter1 and filter2 give
              you all the fclient and fcity nodes.)

              However, if you set
              <xsl:param name="filter1" select="'5'"/>
              <xsl:param name="filter2" select="'Zaanda m'"/>

              then you get only the data for fclient=5 and fcity=Zaandam
              which I'm still assuming is what you want.

              Ben

              --
              Ben Edgington
              Mail to the address above is discarded.
              Mail to ben at that address might be read.

              Comment

              • Sharon Steringa

                #8
                Re: XSL: parameter checking

                Wow, thanks, you are absolutely right! Great!

                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                Working...