|
List Info
Thread: How to subsitute a processing instruction in a string?
|
|
| How to subsitute a processing
instruction in a string? |
  Germany |
2007-07-12 05:25:44 |
I'd like to substitute a processing instruction (a
stylesheet) I have in
a string, so that I can make it dynamic.
This does not work (string gets escaped):
<?python
sspi = '<?xml-stylesheet type="%s"
href="%s"?>' (type, url)
?>
<div py:replace="sspi"
py:if="defined('sspi')" />
Using XML() does not work either:
<div py:replace="XML(sspi)"
py:if="defined('sspi')" />
ParseError: no element found: line 1, column 61
Using kid.ProcessingInstruction to generate an ET.Element
does not work
either:
<?python
from kid import ProcessingInstruction
def xml_stylesheet(url):
return ProcessingInstruction('xml-stylesheet'
' type="%s" href="%s"' % (type,
url))
?>
<root ..>
<div py:replace="ET(sspi)"
py:if="defined('sspi')" />
</root>
File
"/home/chris/lib/tg-py25/lib/python2.5/Genshi-0.4.2-py2
.5.egg/genshi/input.py",
line 41, in ET
tag_name = QName(element.tag.lstrip('{'))
AttributeError: 'function' object has no attribute 'lstrip'
I'm out of options now, can somebody point me in the right
direction?
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Genshi" group.
To post to this group, send email to genshi googlegroups.com
To unsubscribe from this group, send email to
genshi-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/genshi?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: How to subsitute a processing
instruction in a string? |
  Germany |
2007-07-12 16:29:17 |
Christopher Arndt wrote:
> I'd like to substitute a processing instruction (a
stylesheet) I have in
> a string, so that I can make it dynamic.
> This does not work (string gets escaped):
> <?python
> sspi = '<?xml-stylesheet type="%s"
href="%s"?>' (type, url)
> ?>
> <div py:replace="sspi"
py:if="defined('sspi')" />
This is not nice, but it works:
<root xmlns:py="http://genshi.e
dgewall.org/">
<?python
sspi = '<?xml-stylesheet type="%s"
href="%s"?' % (type, url) + '>'
?>
<div py:replace="Markup(sspi)" />
</root>
-- Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Genshi" group.
To post to this group, send email to genshi googlegroups.com
To unsubscribe from this group, send email to
genshi-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/genshi?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: How to subsitute a processing
instruction in a string? |
  Germany |
2007-07-12 22:28:23 |
Christoph Zwerschke schrieb:
> <root xmlns:py="http://genshi.e
dgewall.org/">
> <?python
> sspi = '<?xml-stylesheet type="%s"
href="%s"?' % (type, url) + '>'
> ?>
> <div py:replace="Markup(sspi)" />
> </root>
Thanks, that works nicely. So is "Markup()" the
equivalent of Kid's
"XML()"? I must say, that I find the Genshi user
guide a bit obscure
when you try to find such solutions.
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Genshi" group.
To post to this group, send email to genshi googlegroups.com
To unsubscribe from this group, send email to
genshi-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/genshi?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: How to subsitute a processing
instruction in a string? |
  United States |
2007-07-18 21:10:42 |
On Jul 12, 8:28 pm, Christopher Arndt <chris.ar... web.de> wrote:
> Christoph Zwerschke schrieb:
>
> > <root xmlns:py="http://genshi.e
dgewall.org/">
> > <?python
> > sspi = '<?xml-stylesheet type="%s"
href="%s"?' % (type, url) + '>'
> > ?>
> > <div py:replace="Markup(sspi)" />
> > </root>
>
> Thanks, that works nicely. So is "Markup()"
the equivalent of Kid's
> "XML()"? I must say, that I find the Genshi
user guide a bit obscure
> when you try to find such solutions.
Well, this is a bit of an obscure use case, so it has not
been
addressed. It is a wiki so you can contribute something if
you'd
like.
Markup() and XML() are a bit different. XML() parses the
contents and
includes them in the stream. Markup() simply wraps content
that you
want included without modification, so it can potentially
include
invalid XML. In this case using XML() doesn't work because
it expects
an XML document, which means it has to contain a single root
element,
while your example is just a PI and doesn't have any
elements.
-- Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Genshi" group.
To post to this group, send email to genshi googlegroups.com
To unsubscribe from this group, send email to
genshi-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/genshi?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: How to subsitute a processing
instruction in a string? |
  United States |
2007-07-18 22:29:16 |
On Jul 18, 7:10 pm, Matt Good <m... matt-good.net> wrote:
> On Jul 12, 8:28 pm, Christopher Arndt
<chris.ar... web.de> wrote:
>
> > Christoph Zwerschke schrieb:
>
> > > <root xmlns:py="http://genshi.e
dgewall.org/">
> > > <?python
> > > sspi = '<?xml-stylesheet
type="%s" href="%s"?' % (type, url) +
'>'
> > > ?>
> > > <div py:replace="Markup(sspi)"
/>
> > > </root>
>
> > Thanks, that works nicely. So is
"Markup()" the equivalent of Kid's
> > "XML()"? I must say, that I find the
Genshi user guide a bit obscure
> > when you try to find such solutions.
>
> Well, this is a bit of an obscure use case, so it has
not been
> addressed. It is a wiki so you can contribute
something if you'd
> like.
>
> Markup() and XML() are a bit different. XML() parses
the contents and
> includes them in the stream. Markup() simply wraps
content that you
> want included without modification, so it can
potentially include
> invalid XML. In this case using XML() doesn't work
because it expects
> an XML document, which means it has to contain a single
root element,
> while your example is just a PI and doesn't have any
elements.
To follow up, the Markup() will work unless you have a
filter you want
to use that should be aware of the PI event. In that case
you'll want
to include the event to be output in the stream:
<root xmlns:py="http://genshi.e
dgewall.org/">
<?python
from genshi.core import PI
sspi = (PI, ('xml-stylesheet', 'type="%s"
href="%s"' % (type_, url)),
None)
?>
<div py:replace="[sspi]"/>
</root>
-- Matt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Genshi" group.
To post to this group, send email to genshi googlegroups.com
To unsubscribe from this group, send email to
genshi-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/genshi?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: How to subsitute a processing
instruction in a string? |
  Germany |
2007-07-19 16:02:17 |
Matt Good schrieb:
> To follow up, the Markup() will work unless you have a
filter you want
> to use that should be aware of the PI event. In that
case you'll want
> to include the event to be output in the stream:
>
> <root xmlns:py="http://genshi.e
dgewall.org/">
> <?python
> from genshi.core import PI
> sspi = (PI, ('xml-stylesheet', 'type="%s"
href="%s"' % (type_, url)),
> None)
> ?>
> <div py:replace="[sspi]"/>
> </root>
Thanks, this approach works too. So, to sum up, I now have 4
approaches
to include a dynamic PI in a Kid or Genshi template:
For Kid
-------
1) Pass whole PI in a string and use XML():
<?python
sspi = '<?xml-stylesheet type="%s"
href="%s"?>' % (type, href)
?>
<div py:replace="XML(sspi)"
py:if="defined('sspi')" />
2) Generate the PI with a ProcessingInstruction object and
use directly:
<?python
from kid import ProcessingInstruction as KidPI
sspi = KidPI('xml-stylesheet type="%s"
href="%s"' % (type, href))
?>
<div py:replace="sspi"
py:if="defined('sspi')" />
For Genshi
----------
1) Pass whole PI in a string and use Markup():
<?python
sspi = '<?xml-stylesheet type="%s"
href="%s"?>' % (type, href)
?>
<div py:replace="Markup(sspi)"
py:if="defined('sspi')" />
2) Generate the PI with a PI object and wrap in a markup
stream:
<?python
from genshi.core import PI as GenshiPI
sspi = [(GenshiPI, ('xml-stylesheet', 'type="%s"
href="%s"' %
(type, href)), None)]
?>
<div py:replace="sspi"
py:if="defined('sspi')" />
Thanks for all the comments!
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Genshi" group.
To post to this group, send email to genshi googlegroups.com
To unsubscribe from this group, send email to
genshi-unsubscribe googlegroups.com
For more options, visit this group at http://gr
oups.google.com/group/genshi?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-6]
|
|