Re: XSLT-accessed query params and testing existance

2004-07-08 Thread Kjetil Kjernsmo
On onsdag 7. juli 2004, 18:41, Michael A Nachbaur wrote:
  But then, I need to test whether a parameter exists... In XSP
  that's straightforward, thanks to the many good taglibs, but I
  haven't found anything on checking the parameters in XSLT, is it
  doable?

 Well, the most common method I know of doing that is:

 xsl:param name=foo select=''/

Is that line really necessary?

 xsl:if test=$foo = ''
   !-- Test to see if no value has been supplied --
 /xsl:if
 xsl:if test=not($foo = '')
   !-- Test to see if a value has been supplied --
 /xsl:if

Yhm, yes of course... The reason why I first thought this was inadequate 
was that it checks for an empty string rather than a non-existant 
variable. Which would make a situation where I want to delete a string 
harder to work with. But since you say it, of course, the query 
parameters are not making that distinction, a parameter is passed on 
from a request even if the field wasn't given a value. Which means I 
would have to work around the around problem anyway. So thanks! 

 You can probably clean this up a bit by using named templates.

 xsl:template name=param.foo
     xsl:choose
         xsl:when test=$foo = ''
             xsl:value-of select=$foo/
         /xsl:when
         xsl:otherwise
             xsl:value-of select=foo/
         /xsl:otherwise
     /xsl:choose
 /xsl:template

Yup, nice!

  Is there more documentation on the parameters AxKit pass to XSLT
  somewhere now? I remembered an old thread about them and found it
  in the archives, but that was about all.

 IIRC, by default it adds the query string parameters supplied to the
 URL, and any additional parameters added by any AxKit plugins that
 are supplied.  For instance, you can use one of the
 Apache::AxKit::Plugin::AddXSLParams::* modules to put in additional
 parameters as needed.

Yup, but things like if a xsl:param name=foo select=''/ variable 
declaration is really necessary is rather unclear... 

 Kip wrote a module to parse out the HTTP Request object and supply
 detailed parameters for them (::Request) and I have a module that can
 take values stored in your BasicSession and supply them to your
 stylesheet.

Yup!

  Kip, anything about that in your new book? It's in the mail on its
  way here... :-)

 Good choice!  Its a really great book.  I've been an AxKit regular
 for a while now, and I've learned quite a few things in there.

Good!

 http://nachbaur.com/pgpkey.asc

Uhm, you didn't get the new key right, but I'll take that in a private 
e-mail. :-) 

Best,

Kjetil
-- 
Kjetil Kjernsmo
Astrophysicist/IT Consultant/Skeptic/Ski-orienteer/Orienteer/Mountaineer
[EMAIL PROTECTED]  [EMAIL PROTECTED]  [EMAIL PROTECTED]
Homepage: http://www.kjetil.kjernsmo.net/OpenPGP KeyID: 6A6A0BBC

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XSLT-accessed query params and testing existance

2004-07-08 Thread Michael A Nachbaur
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On July 8, 2004 03:53 am, Kjetil Kjernsmo wrote:
 On onsdag 7. juli 2004, 18:41, Michael A Nachbaur wrote:
   But then, I need to test whether a parameter exists... In XSP
   that's straightforward, thanks to the many good taglibs, but I
   haven't found anything on checking the parameters in XSLT, is it
   doable?
 
  Well, the most common method I know of doing that is:
 
  xsl:param name=foo select=''/

 Is that line really necessary?

Not really.  It mainly can be used to supply a default, non-empty, value.  So, 
if you say:

xsl:param name=foo select='NULL'/

and then later say

xsl:if test=$foo = 'NULL'
  # No value was supplied
/xsl:if

that'd do the trick in determining if simply an empty string was supplied.
  http://nachbaur.com/pgpkey.asc

 Uhm, you didn't get the new key right, but I'll take that in a private
 e-mail. :-)

Blast it!  *sigh*  :-)

- -- 
Michael A. Nachbaur [EMAIL PROTECTED]
http://nachbaur.com/pgpkey.asc
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA7WFfQy51zN2518IRAomrAKDtizeBq2YLGJO74e0nEh3zjnFIkgCgi2OU
w8ysDYB5j5lILQRlSrNvquE=
=dVcR
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XSLT-accessed query params and testing existance

2004-07-08 Thread Kjetil Kjernsmo
On torsdag 8. juli 2004, 16:59, Michael A Nachbaur wrote:
  Is that line really necessary?

 Not really.  It mainly can be used to supply a default, non-empty,
 value.  So, if you say:

 xsl:param name=foo select='NULL'/

 and then later say

 xsl:if test=$foo = 'NULL'
   # No value was supplied
 /xsl:if

 that'd do the trick in determining if simply an empty string was
 supplied.

Ah, that's a good idea! 

But I bumped into something funny, it seems like the line in fact is 
needed for some applications:

My templates now look like this:
  xsl:param name=title select=''/

  xsl:template match=//val:[EMAIL PROTECTED]'title']
xsl:if test=$title = ''
  xsl:value-of select=//story:story/story:title/  
/xsl:if
xsl:if test=not($title = '')
  xsl:value-of select=$title/  
/xsl:if
  /xsl:template

  xsl:param name=minicontent select=''/

  xsl:template match=//val:[EMAIL PROTECTED]'minicontent']
xsl:if test=$minicontent = ''
  xsl:value-of select=//story:story/story:minicontent/  
/xsl:if
xsl:if test=not($minicontent = '')
  xsl:value-of select=$minicontent/  
/xsl:if
  /xsl:template

This works as intended. But if I comment out the variable declaration 
in the xsl:param element, I get an Internal Server Error, and the error 
message:
runtime error: file /news/insert-values-edit.xsl element if
unregistered variable title
...but it happens only if title is not supplied at all. Which means, it 
is more or less needed for robustness.

The two above templates aren't a very nice display of Laziness, as you 
can see... And I need a dozen of those unless I'm able to rewrite it, 
so that's the other, original question... The variable name is 
available to the template in //val:[EMAIL PROTECTED], but the problem is 
making that a variable name... It itches terribly... 

Cheers, 

Kjetil
-- 
Kjetil Kjernsmo
Astrophysicist/IT Consultant/Skeptic/Ski-orienteer/Orienteer/Mountaineer
[EMAIL PROTECTED]  [EMAIL PROTECTED]  [EMAIL PROTECTED]
Homepage: http://www.kjetil.kjernsmo.net/OpenPGP KeyID: 6A6A0BBC

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XSLT-accessed query params and testing existance

2004-07-08 Thread Tod Harter
There is of course an entirely different approach which is possible...
Have your XSP capture the required input parameters and construct some 
output XML containing the data you need. Then you have some added 
flexibility by doing it with perl. I've found that generally thats the 
better overall technique from a standpoint of general web application 
structure, since you probably want to validate and scrub those inputs 
anyway (ie maybe for purposes of avoiding XSS attacks etc.

Kjetil Kjernsmo wrote:
On torsdag 8. juli 2004, 16:59, Michael A Nachbaur wrote:
 

Is that line really necessary?
 

Not really.  It mainly can be used to supply a default, non-empty,
value.  So, if you say:
xsl:param name=foo select='NULL'/
and then later say
xsl:if test=$foo = 'NULL'
 # No value was supplied
/xsl:if
that'd do the trick in determining if simply an empty string was
supplied.
   

Ah, that's a good idea! 

But I bumped into something funny, it seems like the line in fact is 
needed for some applications:

My templates now look like this:
 xsl:param name=title select=''/
 xsl:template match=//val:[EMAIL PROTECTED]'title']
   xsl:if test=$title = ''
 xsl:value-of select=//story:story/story:title/  
   /xsl:if
   xsl:if test=not($title = '')
 xsl:value-of select=$title/  
   /xsl:if
 /xsl:template

 xsl:param name=minicontent select=''/
 xsl:template match=//val:[EMAIL PROTECTED]'minicontent']
   xsl:if test=$minicontent = ''
 xsl:value-of select=//story:story/story:minicontent/  
   /xsl:if
   xsl:if test=not($minicontent = '')
 xsl:value-of select=$minicontent/  
   /xsl:if
 /xsl:template

This works as intended. But if I comment out the variable declaration 
in the xsl:param element, I get an Internal Server Error, and the error 
message:
runtime error: file /news/insert-values-edit.xsl element if
unregistered variable title
...but it happens only if title is not supplied at all. Which means, it 
is more or less needed for robustness.

The two above templates aren't a very nice display of Laziness, as you 
can see... And I need a dozen of those unless I'm able to rewrite it, 
so that's the other, original question... The variable name is 
available to the template in //val:[EMAIL PROTECTED], but the problem is 
making that a variable name... It itches terribly... 

Cheers, 

Kjetil
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: XSLT-accessed query params and testing existance

2004-07-08 Thread Michael A Nachbaur
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On July 8, 2004 09:01 am, Kjetil Kjernsmo wrote:
 On torsdag 8. juli 2004, 16:59, Michael A Nachbaur wrote:
   Is that line really necessary?
 
  Not really.  It mainly can be used to supply a default, non-empty,
  value.  So, if you say:
 
  xsl:param name=foo select='NULL'/
 
  and then later say
 
  xsl:if test=$foo = 'NULL'
    # No value was supplied
  /xsl:if
 
  that'd do the trick in determining if simply an empty string was
  supplied.

 Ah, that's a good idea!

 snip

 The two above templates aren't a very nice display of Laziness, as you
 can see... And I need a dozen of those unless I'm able to rewrite it,
 so that's the other, original question... The variable name is
 available to the template in //val:[EMAIL PROTECTED], but the problem is
 making that a variable name... It itches terribly...

Well, you can either use the magic of Copy  Paste, or you can do some fancy 
footwork with EXSLT.

I don't think CopyPaste needs any explanation.  With EXSLT 
(http://www.exslt.org) you could probably use the eval() function to create 
an XPath expression and evaluate it, to perform your test.

At this point however, I think it might be worth taking a step back and trying 
to determine what you're getting done, and perhaps refactor what you're 
doing, instead of trying to force the XSL params functionality into place.  
Perl-space would be a good spot to look for that.

- -- 
Michael A. Nachbaur [EMAIL PROTECTED]
http://nachbaur.com/pgpkey.asc
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA7YaPvow0fXaFDZQRAtcUAJwO+pAokXjPC6nHg0Q0W+bsYeFoDQCcCKTh
KL/gj0LZ0KzRTDRg9hDfCKw=
=zfth
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XSLT-accessed query params and testing existance

2004-07-08 Thread S . Woodside
On Jul 8, 2004, at 6:53 AM, Kjetil Kjernsmo wrote:
xsl:param name=foo select=''/
Is that line really necessary?
Yes, but you can simplify it to
xsl:param name=foo/
it will automatically default to '' (empty string) if nothing is passed 
in. You need it in order to define the param inside the xslt.

simon
--
http://simonwoodside.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: XSLT-accessed query params and testing existance

2004-07-08 Thread Kjetil Kjernsmo
On torsdag 8. juli 2004, 19:38, Michael A Nachbaur wrote:
 At this point however, I think it might be worth taking a step back
 and trying to determine what you're getting done, and perhaps
 refactor what you're doing, instead of trying to force the XSL params
 functionality into place. Perl-space would be a good spot to look for
 that.

Hmpf! Yep, I guess so. The reason why I rejected doing it in Perl-space 
at first was that I couldn't find a way to not load the data twice. 
Since it is allready available in the document, XSLT seemed ideal to 
get the data from one place in the document to another... 

But it seems I should rethink this, indeed. Thanks to all who responded!

Kip's book just came in the door! Juhuuu! I'm currently being clued in 
about the existence of Dahuts! :-)

Cheers,

Kjetil
-- 
Kjetil Kjernsmo
Astrophysicist/IT Consultant/Skeptic/Ski-orienteer/Orienteer/Mountaineer
[EMAIL PROTECTED]  [EMAIL PROTECTED]  [EMAIL PROTECTED]
Homepage: http://www.kjetil.kjernsmo.net/OpenPGP KeyID: 6A6A0BBC

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XSLT-accessed query params and testing existance

2004-07-07 Thread Michael A Nachbaur
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On July 7, 2004 07:56 am, Kjetil Kjernsmo wrote:
 But this is of little use, because I'd like to have a single template
 replacing all the possible parameters, so instead of $title, I should
 use the
 @name
 (i.e. the name attribute of the val:insert element), to identify the
 parameter. That's a pure XSLT/XQuery question I guess, but I might as
 well ask: Any ideas on how to do that?

 But then, I need to test whether a parameter exists... In XSP that's
 straightforward, thanks to the many good taglibs, but I haven't found
 anything on checking the parameters in XSLT, is it doable?

Well, the most common method I know of doing that is:

xsl:param name=foo select=''/

xsl:if test=$foo = ''
  !-- Test to see if no value has been supplied --
/xsl:if
xsl:if test=not($foo = '')
  !-- Test to see if a value has been supplied --
/xsl:if

You can probably clean this up a bit by using named templates.

xsl:template name=param.foo
xsl:choose
xsl:when test=$foo = ''
xsl:value-of select=$foo/
/xsl:when
xsl:otherwise
xsl:value-of select=foo/
/xsl:otherwise
/xsl:choose
/xsl:template

 Is there more documentation on the parameters AxKit pass to XSLT
 somewhere now? I remembered an old thread about them and found it in
 the archives, but that was about all.

IIRC, by default it adds the query string parameters supplied to the URL, and 
any additional parameters added by any AxKit plugins that are supplied.  For 
instance, you can use one of the Apache::AxKit::Plugin::AddXSLParams::* 
modules to put in additional parameters as needed.

Kip wrote a module to parse out the HTTP Request object and supply detailed 
parameters for them (::Request) and I have a module that can take values 
stored in your BasicSession and supply them to your stylesheet.

 Kip, anything about that in your new book? It's in the mail on its way
 here... :-)

Good choice!  Its a really great book.  I've been an AxKit regular for a while 
now, and I've learned quite a few things in there.

- -- 
Michael A. Nachbaur [EMAIL PROTECTED]
http://nachbaur.com/pgpkey.asc
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA7Ce5Qy51zN2518IRAuYsAJ0fcK4uz+EXyyNTdFgdVNv+HaGLWACdFmIJ
hEVAbuiWrcH45dqYRHa/ng4=
=QWDn
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: XSLT-accessed query params and testing existance

2004-07-07 Thread S . Woodside
xsl:choose
  xsl:when test=$url_parameter != ''
!-- it was set --
  /xsl:when
  xsl:otherwise
!-- it was not set --
  /xsl:otherwise
/xsl:choose
simon
On Jul 7, 2004, at 10:56 AM, Kjetil Kjernsmo wrote:
But then, I need to test whether a parameter exists... In XSP that's
straightforward, thanks to the many good taglibs, but I haven't found
anything on checking the parameters in XSLT, is it doable?
--
http://simonwoodside.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]