473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to check if a parameter is defined in XSLT?

Hi,

Is there a way to check and see if a parameter is defined in XSLT?

I have many stylesheets that all have an <xsl:include> of the same
stylesheet, "foo.xsl".

Foo relies on several parameters that all contain the names of various
XML tags. Foo.xsl then performs a standard action (outputting the
information in HTML) on the tag given by the parameter.

I'm doing this in the context of a content management system. Each
content item has it's own XML structure, so I might have
person.xsl:

car.xsl:
<car>
<model>Gremlin</model>
</car>

<person>
<name>Bob</name>
</person>

Each content type (car, person) has its own XSL, but foo.xsl performs
tasks that need to be done for every content type (generally determining
what locale to display in).

So car.xsl has <xsl:param name="printMeNode" select="string('model')"/>
and person.xsl has <xsl:param name="printMeNode"
select="string('name')"/>. Both car.xsl and person.xsl then do an
xsl:include of foo.xsl.

Then foo.xsl has

xmlns:dynamic="http://exslt.org/dynamic"
....
<xsl:for-each select="dynamic:evaluate($printMeNode)">
<xsl:value-of select="."/>
</xsl:for-each>

(Evaluate is a function that turns a string into a node-set.)

But I'm not the only person who is going to be writing the content type
XSLs, and while I've put dire warnings everywhere I could, I still want
to be able to print an output message if the printMeNode parameter isn't
found so the other developer will know what the heck is going on.

Right now, if printMeNode isn't there, the error message is a cryptic
"Could not find variable with the name of printMeNode". I'm using
Xalan, by the way.

So is there any way to check and ensure that a parameter/variable is
defined? Maybe I'm going about this in the wrong way entirely?

*Any* suggestions, comments will be greatly appreciated.
-------------------
Regards,
BH

--
brandolon (AT) gmail.mybrain.com - take out my brain to reach me

Jul 20 '05 #1
5 4788

Just define the parameter in the stylesheet wher eit is used with some
dummy value, you can then test if it still has that value and issue an
xsl:message warning.

David
Jul 20 '05 #2
> Just define the parameter in the stylesheet wher eit is used with some
dummy value, you can then test if it still has that value and issue an
xsl:message warning.

David


Well, I'm not worried so much about getting bad value as I am worried
about other developers not knowing about (or understanding) the
parameters that this master stylesheet I'm writing requires. And if
they don't know about the parameter, they won't include it in their
sheets, so I won't have a dummy value to check against.

The entire system is absurdly complex, and I want to make life as easy
as possible for those who will follow me. So if I can just print out a
message saying, "Hey, you forgot to define this parameter. Here's what
it is and here's why you need it," rather than having Xalan issue some
esoteric error message.

Thanks for the suggestion though. I'd definitely keep it in mind for
other situations.
----------------
Regards,
BH

--
brandolon (AT) gmail.mybrain.com - take out my brain to reach me

Jul 20 '05 #3

"Brandolon Hill" <br*******@gmail.mybrain.com> wrote in message
news:ct**********@stan.redhat.com...
Just define the parameter in the stylesheet wher eit is used with some
dummy value, you can then test if it still has that value and issue an
xsl:message warning.

David


Well, I'm not worried so much about getting bad value as I am worried
about other developers not knowing about (or understanding) the parameters
that this master stylesheet I'm writing requires. And if they don't know
about the parameter, they won't include it in their sheets, so I won't
have a dummy value to check against.

The entire system is absurdly complex, and I want to make life as easy as
possible for those who will follow me. So if I can just print out a
message saying, "Hey, you forgot to define this parameter. Here's what it
is and here's why you need it," rather than having Xalan issue some
esoteric error message.

Thanks for the suggestion though. I'd definitely keep it in mind for
other situations.

Savid's suggestion is perfectly usable in your case.

Cheers,
Dimitre Novatchev.
Jul 20 '05 #4
Brandolon Hill <br*******@gmail.mybrain.com> writes:
Just define the parameter in the stylesheet wher eit is used with some
dummy value, you can then test if it still has that value and issue an
xsl:message warning.

David


Well, I'm not worried so much about getting bad value as I am worried
about other developers not knowing about (or understanding) the
parameters that this master stylesheet I'm writing requires. And if
they don't know about the parameter, they won't include it in their
sheets, so I won't have a dummy value to check against.

The entire system is absurdly complex, and I want to make life as easy
as possible for those who will follow me. So if I can just print out a
message saying, "Hey, you forgot to define this parameter. Here's what
it is and here's why you need it," rather than having Xalan issue some
esoteric error message.

Thanks for the suggestion though. I'd definitely keep it in mind for
other situations.
----------------
Regards,
BH

--
brandolon (AT) gmail.mybrain.com - take out my brain to reach me


You misunderstood my suggestion.

there is no reason for you ever to reference an undefined varoable in
xslt. In any stylesheet that uses $foo you can put
<xsl:param name="foo" select="'qwertyuiop'"/>
at the top level of the file so it is always defined.

If you expect that this parameter to be defined on the external call to
the processor, or in an importing stylesheet then your styesheet that is
using $foo can do

<xsl:if test="$foo='qwertyuiop'">
<xsl:message>
You forgot to set the parameter $foo
It should have value 42 unless ....
</xsl:message>
</xsl:if

David

Jul 20 '05 #5
> You misunderstood my suggestion.

Ah, yes I did. I must not have eaten my Wheaties yesterday. Thanks
again for your help! It is most appreciated.
------------------
Regards,
BH

--
brandolon (AT) gmail.mybrain.com - take out my brain to reach me

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mini Mouse | last post by:
Hiya folks, I'm getting the following error(s) below and I'm at a bit of a loss as to how to correct it. When I give it a parameter it then complains it needs two parameters and the second one...
2
by: Neal | last post by:
I need to know how to pass a parameter from PERL to an XSLT when using that XSLT to transform XML. For instance, I'd like to pass a paramter that I retrieve from the queryString and pass it into...
0
by: Thomas Scheffler | last post by:
Hi, I have several xslt documents that import each other in a specific way to allow resulting documents to be layout in a common way. In the "master stylesheet" I need some kind of test to check...
2
by: Craig Petrie | last post by:
The following transformation puzzles me when trying to transform XML to XML. I get an exception "THE EXPRESSION PASSED TO THIS METHOD SHOULD RESULT IN A NODESET" at the last line...
1
by: cameron | last post by:
I am attempting to pass in an XmlDocument as a parameter to a transform: from my sample ASPX page: string BaseDir = "/cameron/Play/ComplexParam/"; XmlDocument XSL = new XmlDocument();...
0
by: stevag | last post by:
I have stored a variable ABC in a ASP.NET page and I use xsltArglist.AddParam in order to add this variable as a parameter to the binded XSLT transformation. In the associated .xslt file I use...
6
by: Jody Gelowitz | last post by:
I have run into an issue with variable scope within an XSLT document that is translated in VS.NET 2.0. Under VS.NET 1.1 (XslTransform), this code works fine. However, when using VS.NET 2.0...
10
by: bbembi_de | last post by:
Hello everyone, is it possible to give a transformation a input parameter? I want to use this parameter as a variable in my transformation. thanks. bye bembi
5
by: Jason | last post by:
Hi all, Are you familiar with Safari? I have a site that works perfectly in IE6 IE7 FF2 FF3 but not in the latest Safari. When I test xsltProcessor, there is a error as following, I have dealt...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.