473,322 Members | 1,405 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,322 software developers and data experts.

is this stylesheet valid?

hi,

i'm porting some xsl code from .net 1.1 to 2.0 and I have come across a
transform which works in .net 1.1 and works in mxsml but does not work in
..net 2.0. the stylesheet is this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="foo">
<xsl:param name="param1"/>
<xsl:value-of select="$param1/*"/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

and the input file is simply

<foo />

so $param1 has no value (empty string? empty node set? I'm not sure)

with .net 2.0 I get an error message Unhandled Exception:
System.Xml.XPath.XPathException: Expression must evaluate to a node-set. I'm
guessing this is because the default parameter value is an empty string.

in the real stylesheet, the parameter (if it is passed in) will be a node
set. so to make sure I don't evaluate an illegal expression, I need to be
able to tell whether the parameter value is an empty string (i.e. default)
or a node set. how can I achieve this?

Andy
May 31 '07 #1
5 3284
* Andy Fish wrote in microsoft.public.dotnet.xml:
<xsl:param name="param1"/>
<xsl:value-of select="$param1/*"/>
>in the real stylesheet, the parameter (if it is passed in) will be a node
set. so to make sure I don't evaluate an illegal expression, I need to be
able to tell whether the parameter value is an empty string (i.e. default)
or a node set. how can I achieve this?
You could simply check whether $param1 evaluates to a true value, e.g.

<xsl:if text='$param1'>
<xsl:value-of select="$param1/*"/>
</xsl:if>

should do.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
May 31 '07 #2
Andy Fish wrote:
i'm porting some xsl code from .net 1.1 to 2.0 and I have come across a
transform which works in .net 1.1 and works in mxsml but does not work in
.net 2.0. the stylesheet is this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="foo">
<xsl:param name="param1"/>
<xsl:value-of select="$param1/*"/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

and the input file is simply

<foo />

so $param1 has no value (empty string? empty node set? I'm not sure)

with .net 2.0 I get an error message Unhandled Exception:
System.Xml.XPath.XPathException: Expression must evaluate to a node-set. I'm
guessing this is because the default parameter value is an empty string.
If I understand <http://www.w3.org/TR/xslt#variable-valuescorrectly
then the default value is the empty string.
in the real stylesheet, the parameter (if it is passed in) will be a node
set. so to make sure I don't evaluate an illegal expression, I need to be
able to tell whether the parameter value is an empty string (i.e. default)
or a node set. how can I achieve this?
To avoid the exception it should suffice to set
<xsl:param name="param1" select="/.."/>
as that way the value is an empty node set and then
<xsl:value-of select="$param1/*"/>
does not give an exception.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 31 '07 #3
Andy Fish wrote:
hi,

i'm porting some xsl code from .net 1.1 to 2.0 and I have come across a
transform which works in .net 1.1 and works in mxsml but does not work in
.net 2.0. the stylesheet is this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="foo">
<xsl:param name="param1"/>
<xsl:value-of select="$param1/*"/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

and the input file is simply

<foo />

so $param1 has no value (empty string? empty node set? I'm not sure)

with .net 2.0 I get an error message Unhandled Exception:
System.Xml.XPath.XPathException: Expression must evaluate to a node-set. I'm
guessing this is because the default parameter value is an empty string.

in the real stylesheet, the parameter (if it is passed in) will be a node
set. so to make sure I don't evaluate an illegal expression, I need to be
able to tell whether the parameter value is an empty string (i.e. default)
or a node set. how can I achieve this?

Andy


rather than have it default to an empty string, and then having to test
for that to avoid using the variable in path expressions, it's usually
simpler just to make it default to an empty node set, add
<xsl:param name="param1" select="/.."/>

David
--
http://dpcarlisle.blogspot.com
Jun 1 '07 #4

"David Carlisle" <da********@dcarlisle.demon.co.ukwrote in message
news:46**************@dcarlisle.demon.co.uk...
Andy Fish wrote:
>hi,

i'm porting some xsl code from .net 1.1 to 2.0 and I have come across a
transform which works in .net 1.1 and works in mxsml but does not work in
.net 2.0. the stylesheet is this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="foo">
<xsl:param name="param1"/>
<xsl:value-of select="$param1/*"/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

and the input file is simply

<foo />

so $param1 has no value (empty string? empty node set? I'm not sure)

with .net 2.0 I get an error message Unhandled Exception:
System.Xml.XPath.XPathException: Expression must evaluate to a node-set.
I'm guessing this is because the default parameter value is an empty
string.

in the real stylesheet, the parameter (if it is passed in) will be a node
set. so to make sure I don't evaluate an illegal expression, I need to be
able to tell whether the parameter value is an empty string (i.e.
default) or a node set. how can I achieve this?

Andy



rather than have it default to an empty string, and then having to test
for that to avoid using the variable in path expressions, it's usually
simpler just to make it default to an empty node set, add
<xsl:param name="param1" select="/.."/>

David
--
http://dpcarlisle.blogspot.com
Thanks david, that's pretty much what I ended up doing

unfortunately there were quite a lot of templates with this optional
parameter, although only one of them actually used the parameter. they are
calling each other like this:

<xsl:template match="...">
<xsl:param name="param1"/>
....
<xsl:apply-templates>
<xsl: with-param name="param1" select="$param1" </xsl:template>
</xsl:apply-templates/>
</xsl:template >

now, if any one of them gets called without a parameter, it passes in the
blank parameter into the ones it calls (rather than not passing in a
parameter - hence the default value does not apply), so this meant I had to
put the default parameter into every one of the templates, not just the one
that needed it.

so as well as some way of telling whether a variable contains a node set,
string or RTF, I would also like to have an option on <xsl:call-template>
and <xsl:apply templatethat said:

if this parameter was passed in to me, pass the parameter into the next
template,. otherwise don't pass in the parameter into the next template

Andy
Jun 5 '07 #5

Andy Fish <aj****@blueyonder.co.ukwrote in
<Vq*******************@text.news.blueyonder.co.uk> :
"David Carlisle" <da********@dcarlisle.demon.co.ukwrote
in message news:46**************@dcarlisle.demon.co.uk...
>Andy Fish wrote:
>>so $param1 has no value (empty string? empty node set?
I'm not sure)

rather than have it default to an empty string, and then
having to test for that to avoid using the variable in
path expressions, it's usually simpler just to make it
default to an empty node set, add <xsl:param
name="param1" select="/.."/>

unfortunately there were quite a lot of templates with
this optional parameter, although only one of them
actually used the parameter.
[...]
so as well as some way of telling whether a variable
contains a node set, string or RTF, I would also like to
have an option on <xsl:call-templateand <xsl:apply
templatethat said:

if this parameter was passed in to me, pass the parameter
into the next template,. otherwise don't pass in the
parameter into the next template
Read XSLT2 spec, 10.1.2 and rejoice. (Although I must say I
don't see how precisely that would help you, since from the
description of your predicament it would seem you'd have to
specify the tunneling everywhere anyway.)

--
Pavel Lepin
Jun 5 '07 #6

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

Similar topics

3
by: Sarah Haskins | last post by:
I have a few questions about this problem I'm having involving XML, DTD, and XSL. I'm working with this DTD which defines a stylesheet, as such... <?xml version="1.0" encoding="UTF-8"?>...
0
by: Andy Dingley | last post by:
I'm writing XSLT to transform fntg-schema (our own project's document schema) into PartnerML, a HTML-like XML dialect used for mobile phones. I'm using XMLSPy 4.4 to do this. The schema for...
8
by: Ian Fitchet | last post by:
Hi, You'll excuse me if this has been answered before but I must have missed it on my travels: Is there a definitive style sheet with includes a definition for everything that a particular...
2
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: August 28, 2002 Version: 1.15 URL: http://css.nu/faq/ciwas-aFAQ.html...
0
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: April 10, 2003 Version: 1.16 URL: http://css.nu/faq/ciwas-aFAQ.html Maintainer:...
1
by: Frances | last post by:
sometimes when checking css syntax at the w3c checker I get this mesage: To work as intended, your CSS style sheet needs a correct document parse tree. This means you should use valid HTML. ...
11
by: jesdynf | last post by:
I'm having trouble applying a stylesheet to content I'm generating after the fact. Here's the sample code: <html> <head> <title>CSS/DOM Problem Example</title> <style type="text/css">...
7
by: Andy Fish | last post by:
hi, i'm porting some xsl code from .net 1.1 to 2.0 and I have come across a transform which works in .net 1.1 and works in mxsml but does not work in ..net 2.0. the stylesheet is this: <?xml...
1
by: Puja | last post by:
hi all, On my page, i have external stylesheet <link id="sbSiteCSS" rel="stylesheet" type="text/css" runat="server" /> whose href is determined on page_load protected void Page_Load(object...
8
by: Mark Shroyer | last post by:
I just completed a new design for a personal web site. After finishing the basic CSS stuff and double-checking it in Safari, FF, Opera, et al., I put on my war paint and fired up IE7 to figure out...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.