You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Thomas F. O'Connell" <tf...@netcentral.com> on 2003/07/16 20:03:33 UTC

Escaping Stylesheet Parameters

I've got a process that is applying a stylesheet to an XML document, and
the process needs to set a parameter in the stylesheet. What I'm having
trouble with, currently, is that the parameter might have reserved
characters in it (I'm currently struggling with '). Now I want the
parameter to be something I can display in an unescaped format once the
transformation is done.

Currently, as soon as I pass the parameter, I'm getting this from Xalan:

PlatformSupport/DOMStringHelper.cpp:523: void substring(const
XalanDOMString&, XalanDOMString&, unsigned int, unsigned int): Assertion
`theStartIndex + theLength <= theStringLength' failed.

This seems to be happening as soon as the parameter is set (or the
attempt is made to set the parameter), as I've removed all references to
the parameter from the stylesheet just to see whether I could
successfully set it.

Is there any way to pass an unescaped parameter with reserved characters
to a stylesheet? Or is there a way of escaping it before setting it and
then unescaping it during the transformation process?

Thanks!

-tfo


Re: Escaping Stylesheet Parameters

Posted by Joseph Kesselman <ke...@us.ibm.com>.



Theoretically, you should be able to just pass the parameter as a string;
no escaping should be required on input.

However, when the data is output it will pass though a serializer, and at
that time may have to be escaped to fit the code page or (if outputting to
XML or HTML) to fit constraints on what characters may appear where.

If that is what you're seeing, it's correct operation. If that isn't what
you're seeing, please provide a more specific illustration of what you're
doing, what you expect to happen, and what's happening instead, so we can
determine whether there is a real problem or not.

______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk


Re: Escaping Stylesheet Parameters

Posted by da...@us.ibm.com.



> Out of curiosity, does the latest Xalan support the feature of XPath 2.0
> that will provide a more complete solution? Also, what is that feature?
> Glancing at the definition of String Literal in the spec didn't really
> open my eyes...

There is no support in Xalan-C++ for XPath 2.0.  The feature is described
here:

   http://www.w3.org/TR/xpath20/#id-literals

   "He said, ""I don't like it.""" denotes a string containing two
   quotation marks and one apostrophe.

Dave


Re: Escaping Stylesheet Parameters

Posted by "Thomas F. O'Connell" <tf...@netcentral.com>.
Thanks for the tip. I think I can safely trap for one of these
scenarios. My interface will more commonly use the single quote, so I
can use the ' ... " ... ' form.

Out of curiosity, does the latest Xalan support the feature of XPath 2.0
that will provide a more complete solution? Also, what is that feature?
Glancing at the definition of String Literal in the spec didn't really
open my eyes...

-tfo

On Wed, 2003-07-16 at 16:10, david_n_bertoni@us.ibm.com wrote:
> Yes, you use the " character to delimit the literal:
> 
>    "This is a string literal with a ' character in it."
> 
> and:
> 
>    'This is a string literal with a " character in it.'
> 
> What you can't do is have a string literal with both a " and ' character,
> since one must be used as the delimiter.
> 
> Dave


Re: Escaping Stylesheet Parameters

Posted by da...@us.ibm.com.



> > There's no syntax limitation here that's unique to Xalan or any other
XSLT
> > processor.  A param in Xalan-C++ is an XPath expression, so, if you
want a
> > string literal, you have to provide one.  The limitation that a string
> > literal delimited by a ' cannot contain a ' as a character, and the
> > analogous case with " is a limitation of XPath 1.0.  XPath 2.0 has a
> > mechanism to handle these cases.
>
> Well, that's my real problem, then: the XPath 1.0 definition of a string
> literal. Is there a standard practice solution to passing a parameter
> that contains a '?

Yes, you use the " character to delimit the literal:

   "This is a string literal with a ' character in it."

and:

   'This is a string literal with a " character in it.'

What you can't do is have a string literal with both a " and ' character,
since one must be used as the delimiter.

Dave


Re: Escaping Stylesheet Parameters

Posted by "Thomas F. O'Connell" <tf...@netcentral.com>.
On Wed, 2003-07-16 at 14:56, david_n_bertoni@us.ibm.com wrote:
> OK, the assert is fixed now, so you'll get a proper error about an invalid
> expression.

Well, that's good news.

> This might best be done with an extension function.  In the Xalan 1.7
> release, we should have an extension function that does this built into the
> processor.

Based on what you say later, I'm not sure it's going to matter.

> There's no syntax limitation here that's unique to Xalan or any other XSLT
> processor.  A param in Xalan-C++ is an XPath expression, so, if you want a
> string literal, you have to provide one.  The limitation that a string
> literal delimited by a ' cannot contain a ' as a character, and the
> analogous case with " is a limitation of XPath 1.0.  XPath 2.0 has a
> mechanism to handle these cases.

Well, that's my real problem, then: the XPath 1.0 definition of a string
literal. Is there a standard practice solution to passing a parameter
that contains a '?

> I don't understand what you're saying here.  I don't have a copy of "The
> XSL Companion," and I don't know what templates would have to do with it.
> Again, a concrete example would help.

Sorry. The XSL Companion is one of my favorite XSL references:

http://www.aw-bc.com/catalog/academic/product/0,4096,0201770830,00.html

I couldn't find source examples anywhere, but there's a subsection
called "Escaping significant characters" in which Bradley provides a
"String replacement template" that basically does what its name implies.
And I'm sure there are other, similar extension functions, but if I
can't even get the parameter to the stylesheet in the correct format, it
doesn't really matter.

Unless I can escape it prior to passing it to the stylesheet and then
replace it via the stylesheet once it's there...

Anyway, I guess this is more of an XSL question now, eh?

Thanks for the feedback!

-tfo 


Re: Escaping Stylesheet Parameters

Posted by da...@us.ibm.com.



> I'm using Xalan C++ 1.4, but I'm actually using it with XML::Xalan 0.44
> (with a few modifications to make it compatible with the C++ version;
> it's technically compatible with 1.3). I'll move to Xalan C++ 1.5 (or
> 1.6, if available) when Xerces Perl has moved out of beta for 2.3.0 and
> I've modified XML::Xalan again as necessary.

OK, the assert is fixed now, so you'll get a proper error about an invalid
expression.

> What I'm basically trying to do is collect a search term from a web form
> and then send both an escaped version (for URI encoding) and an
> unescaped version (for display purposes) to Xalan. I figured the
> escaping would be easier done in Perl.

This might best be done with an extension function.  In the Xalan 1.7
release, we should have an extension function that does this built into the
processor.

> It looks like I'm running up against the syntax limitations of the
> XML::Xalan::Transformer library, which seems to require that non-numeric
> parameters to stylesheets be passed between single quotation marks via
> the set_stylesheet_param method.

There's no syntax limitation here that's unique to Xalan or any other XSLT
processor.  A param in Xalan-C++ is an XPath expression, so, if you want a
string literal, you have to provide one.  The limitation that a string
literal delimited by a ' cannot contain a ' as a character, and the
analogous case with " is a limitation of XPath 1.0.  XPath 2.0 has a
mechanism to handle these cases.

> If I'm forced to escape the ' character in Perl prior to sending a
> parameter to Xalan to avoid the assertion, am I pretty much forced to do
> escaping via the stylesheet using a template (a la Bradley in The XSL
> Companion)?

I don't understand what you're saying here.  I don't have a copy of "The
XSL Companion," and I don't know what templates would have to do with it.
Again, a concrete example would help.

Dave


Re: Escaping Stylesheet Parameters

Posted by "Thomas F. O'Connell" <tf...@netcentral.com>.
David,

Thanks for the quick response.

I'm using Xalan C++ 1.4, but I'm actually using it with XML::Xalan 0.44
(with a few modifications to make it compatible with the C++ version;
it's technically compatible with 1.3). I'll move to Xalan C++ 1.5 (or
1.6, if available) when Xerces Perl has moved out of beta for 2.3.0 and
I've modified XML::Xalan again as necessary.

Upon further inspection, it looks like what I'm dealing with is a
Perl/C++ issue, not an XSL(T) issue.

What I'm basically trying to do is collect a search term from a web form
and then send both an escaped version (for URI encoding) and an
unescaped version (for display purposes) to Xalan. I figured the
escaping would be easier done in Perl.

It looks like I'm running up against the syntax limitations of the
XML::Xalan::Transformer library, which seems to require that non-numeric
parameters to stylesheets be passed between single quotation marks via
the set_stylesheet_param method.

So I'm generating that assertion, I think, when the string length is
calculated on the full string but the string is parsed only until it
hits a ', which is something I need to allow in the search.

If I'm forced to escape the ' character in Perl prior to sending a
parameter to Xalan to avoid the assertion, am I pretty much forced to do
escaping via the stylesheet using a template (a la Bradley in The XSL
Companion)?

Thanks!

-tfo

On Wed, 2003-07-16 at 13:15, david_n_bertoni@us.ibm.com wrote:
> I believe the assert is a bug that has since been fixed.  What version of
> Xalan-C are you using?
> 
> You cannot "escape" stylesheet parameters using XML entities, if that's
> what you're trying to do.  If you're dealing with C++ escaping issues,
> that's different.  You may also be having problems because your parameters
> are XPath string literals,
> 
> Can you provide a trivial stylesheet, input document, and parameter value
> you want to set, so we can understand what you're trying to do?  Otherwise,
> I don't know what we can do to help.
> 
> Thanks!
> 
> Dave


Re: Escaping Stylesheet Parameters

Posted by da...@us.ibm.com.



Hi Thomas,

I believe the assert is a bug that has since been fixed.  What version of
Xalan-C are you using?

You cannot "escape" stylesheet parameters using XML entities, if that's
what you're trying to do.  If you're dealing with C++ escaping issues,
that's different.  You may also be having problems because your parameters
are XPath string literals,

Can you provide a trivial stylesheet, input document, and parameter value
you want to set, so we can understand what you're trying to do?  Otherwise,
I don't know what we can do to help.

Thanks!

Dave



                                                                                                                                       
                      "Thomas F.                                                                                                       
                      O'Connell"               To:      xalan-c-users@xml.apache.org                                                   
                      <tfo@netcentral.         cc:                                                                                     
                      com>                     Subject: Escaping Stylesheet Parameters                                                 
                                                                                                                                       
                      07/16/2003 11:03                                                                                                 
                      AM                                                                                                               
                      Please respond                                                                                                   
                      to xalan-dev                                                                                                     
                                                                                                                                       



I've got a process that is applying a stylesheet to an XML document, and
the process needs to set a parameter in the stylesheet. What I'm having
trouble with, currently, is that the parameter might have reserved
characters in it (I'm currently struggling with '). Now I want the
parameter to be something I can display in an unescaped format once the
transformation is done.

Currently, as soon as I pass the parameter, I'm getting this from Xalan:

PlatformSupport/DOMStringHelper.cpp:523: void substring(const
XalanDOMString&, XalanDOMString&, unsigned int, unsigned int): Assertion
`theStartIndex + theLength <= theStringLength' failed.

This seems to be happening as soon as the parameter is set (or the
attempt is made to set the parameter), as I've removed all references to
the parameter from the stylesheet just to see whether I could
successfully set it.

Is there any way to pass an unescaped parameter with reserved characters
to a stylesheet? Or is there a way of escaping it before setting it and
then unescaping it during the transformation process?

Thanks!

-tfo