Re: [xslt] Python bindings, escaping problems




On 14 Jan 2005, at 09:21, Daniel Veillard wrote:

On Thu, Jan 13, 2005 at 11:32:56PM +0000, Neil Dunn wrote:
I am attempting to parse a number of string parameters using the
applyStylesheet(document, parameters_dictionary),
this works as expected and I have properly wrapped the string in
quotation marks so that it is interpreted as a string rather than an
xpath query.

I don't understand your problem. Why do you need to interpret the value, the library does it ? And also I don't see why the string would an xpath query. Give a concrete example.


As an example from this page: http://xmlsoft.org/XSLT/python.html

When applying a stylesheet to a document with string parameters you have to do something like so:

result = style.applyStylesheet(doc, { "bar": "'success'" })

The comment about double quoting is:

Note that the string passed "success" had to be quoted, otherwise it is interpreted as an XPath query for the childs of root named "success".

Therefore I cannot do something as follows:

result = style.applyStylesheet(doc, { "bar": "'dog\'s'" })

The apostrophe within the string, the one between the g and the s causes an error within libxslt when interpreting the string, giving the error:

	Evaluating user parameter bar failed

So, what seems like a possible solution is to replace all apostrophes within the string with the code ' before wrapping it in the outermost apostrophes and passing it into the applyStylesheet function. The parameter can now be parsed within the dictionary, but this creates problems with the result ...

The problem that now seems to occur is that if the string passed in is a well formed xml fragment which I wish to add to a document, the apostrophe marks that represent a part of the markup are now escaped, and the result document with the appended xml fragment is no longer well formed.

The above problems also occur if instead of working with apostrophes for the outermost wrapping mark; double quote marks are used. This is even worse, as there are generally a lot of double quotes in xml documents occurring as markup.

If there is no way of passing in a document fragment as a string in this way I'm going to have to write a lot more code for what should be a simple thing, so I was hoping there was an easy answer to my escaping problems.

Thanks, Neil

Daniel

--
Daniel Veillard | Red Hat Desktop team http://redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
_______________________________________________
xslt mailing list, project page http://xmlsoft.org/XSLT/
xslt gnome org
http://mail.gnome.org/mailman/listinfo/xslt



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]