XSL: parameter checking

S

Sharon

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=$FILTER1][$FIELD2=$FILTER2]"
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
 
J

Janwillem Borleffs

Sharon said:
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=$FILTER1][$FIELD2=$FILTER2]"
mode="tableData" />
</xsl:variable>

select="general/data/rows/row/fvalues[$FIELD1=$FILTER1 and
$FIELD2=$FILTER2]"


JW
 
B

Ben Edgington

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=$FILTER1][$FIELD2=$FILTER2]"
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

Give the expression

"general/data/rows/row/fvalues[$FIELD1=$FILTER1 and $FIELD2=$FILTER2]"

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
 
S

Sharon Steringa

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=$filter1][fcity=$filter2]"
mode="tableData"
that is when I change the first parameter into a specific node. But
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(column 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
 
B

Ben Edgington

Sharon Steringa said:
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=$filter1][fcity=$filter2]"
mode="tableData"
that is when I change the first parameter into a specific node. But
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(column 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

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
 
S

Sharon Steringa

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="Sleutelveld" type="number" visible="True" />
<fusername caption="Username" type="number" visible="True"/>
<fname caption="Naam" type="text" visible="True" />
<fcity caption="Woonplaats" type="text" visible="True" />
<factive caption="Active" type="text" visible="False" />
<fdebno caption="Debiteurnr" type="number" visible="True" />
<fpassword caption="password" type="text" visible="False" />
</cols>
<rows>
<row>
<id value="32" />
<fvalues>
<fclient>1</fclient>
<fid>13</fid>
<fusername>Pietje</fusername>
<fname>Pieters 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>Willie</fusername>
<fname>Willie Bruining</fname>
<fcity>Blijham</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>Bertje</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>Billie</fusername>
<fname>Billie Bruining</fname>
<fcity>Billieham</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>Pietje</fusername>
<fname>Bob Autotransport B.V.</fname>
<fcity>Zaandam</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>Sjoerd</fusername>
<fname>Sjoerd de Vries</fname>
<fcity>Billieham</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:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:dates="urn:rdcpro-com:dates">
<xsl:eek:utput method="html" encoding="UTF-8"/>
<xsl:param name="username" select="general/data/rows/row"/>
<xsl:param name="field1" select="'fclient'"/>
<xsl:param name="filter1" select="$username/fvalues/fclient"/>
<xsl:param name="field2" select="'fcity'"/>
<xsl:param name="filter2" select="$username/fvalues/fcity"/>
<xsl:param name="direction">ascending</xsl:param>
<xsl:param name="sortBy">fusername</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="$direction"/><br/>
Sort Column:
<xsl:value-of select="$sortBy"/>
</div>
<table border="1" class="results" align="center" cellpadding="5"
cellspacing="0">
<tr>
<th>
<a class="clickanchor" onclick="renderData('fclient');">
<xsl:value-of select="cols/fclient/@caption"/>
</a>
</th>
<th>
<a class="clickanchor" onclick="renderData('fid');">
<xsl:value-of select="cols/fid/@caption"/>
</a>
</th>
<th>
<a class="clickanchor" onclick="renderData('fusername');">
<xsl:value-of select="cols/fusername/@caption"/>
</a>
</th>
<th>
<a class="clickanchor" onclick="renderData('fname');">
<xsl:value-of select="cols/fname/@caption"/>
</a>
</th>
<th>
<a class="clickanchor" onclick="renderData('fcity');">
<xsl:value-of select="cols/fcity/@caption"/>
</a>
</th>
<th>
<a class="clickanchor" onclick="renderData('fdebno');">
<xsl:value-of select="cols/fdebno/@caption"/>
</a>
</th>
</tr>
<xsl:apply-templates select="msxsl:node-set($tableData)/fvalues">
<xsl:sort select="*[name()=$sortBy]" order="{$direction}"/>
</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(current())]/@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
 
B

Ben Edgington

Sharon Steringa said:
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:

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.
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

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

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="'Zaandam'"/>

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

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top