[Templates] T::P::XML::XPath improvements

Mark Fowler mark@indicosoftware.com
Mon, 11 Mar 2002 11:10:51 +0000 (GMT)


  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

--0-993785408-1015844768=:8690
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID: <Pine.BSF.4.40.0203111108221.8690@eviledna.indicosoftware.com>

Hi.

Been playing with this a lot this weekend.  Thanks to #axkit-dahut for
their help.

*Anyway*, I've made some changes to the Template::Plugin::XML::XPath
plugin that effects the way that it supports rendering out undefined tags
with views.  Previously the examples in the plugin pod would render the
whole thing straight through as a string.  This is okay, but breaks for
things like

   <p>This is some <red>red</red> text</p>

Where <p> hasn't been defined.  As everything including and below <p> is
rendered as a string I literally get

   <p>This is some <red>red</red> text</p>

Back again rather than <red> being processed though

  [% BLOCK red %]<font color="red">[% item.content(view) %]</font>[% END %]

To give

  <p>This is some <font color="red">red</font> text</p>

So I made some changes.  This involved having T::P::XML::XPath add
"starttag" and "endtag" methods to XML::XPath::Node::Element so that
the default handling for xmlstring (unknown tags) is now

[% BLOCK xmlstring; item.starttag; item.content(view); item.endtag; END %]

This is all covered in the attached diff.

Oh, I also added some "| html" filters to the examples too (as the output
of XML::XPath will have converted &amp; to & already so you need to
convert them back again).

Later.

Mark.

-- 
  Mark Fowler
  Technology Developer
  http://www.indicosoftware.com/


--0-993785408-1015844768=:8690
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME=diff
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.BSF.4.40.0203111106080.8690@eviledna.indicosoftware.com>
Content-Description: 
Content-Disposition: ATTACHMENT; FILENAME=diff

PyAuZGVmYXVsdHMuY2ZnDQo/IGJsaWINCj8gZGlmZg0KPyBNYWtlZmlsZQ0K
PyBwbV90b19ibGliDQo/IHQvZGJpX3Rlc3QuY2ZnDQo/IHQvdGVzdC9zcmMv
ZXZhbHBlcmwudHRjD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
PiAmIDwvZm9vPg0KKyMtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tDQorDQor
c3ViIHN0YXJ0dGFnIHsNCisgICAgbXkgKCRzZWxmKSA9IEBfOw0KKyAgICBt
eSAkb3V0cHV0ID0gICI8Ii4gJHNlbGYtPmdldE5hbWUoKTsNCisgICAgZm9y
ZWFjaCBteSAkYXR0ciAoJHNlbGYtPmdldEF0dHJpYnV0ZXMoKSkNCisgICAg
ew0KKwkkb3V0cHV0IC49ICRhdHRyLT50b1N0cmluZygpOw0KKyAgICB9DQor
ICAgICRvdXRwdXQgLj0gIj4iOw0KKyAgICByZXR1cm4gJG91dHB1dDsNCit9
DQorDQorc3ViIGVuZHRhZyB7DQorICAgIG15ICgkc2VsZikgPSBAXzsNCisg
ICAgcmV0dXJuICI8LyIuICRzZWxmLT5nZXROYW1lKCkgLiAiPiI7DQorfQ0K
Kw0KICM9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0NCiBwYWNrYWdlIFhN
TDo6WFBhdGg6Ok5vZGU6OlRleHQ7DQogIz09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PQ0KSW5kZXg6IHQveHBhdGgudA0KPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PQ0KUkNTIGZpbGU6IC90ZW1wbGF0ZS10b29sa2l0L1RlbXBsYXRlMi90
L3hwYXRoLnQsdg0KcmV0cmlldmluZyByZXZpc2lvbiAyLjcNCmRpZmYgLXUg
LXIyLjcgeHBhdGgudA0KLS0tIHQveHBhdGgudAkyMDAxLzA2LzI1IDEwOjU1
OjA3CTIuNw0KKysrIHQveHBhdGgudAkyMDA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