Re: is there some way to do eval() for XSLT? [long]
by Wren Argetlahm other posts by this author
Aug 2 2005 4:34AM messages near this date
view in the new Beta List Site
Re: XML::Twig pre-release testing
|
Re: is there some way to do eval() for XSLT? [long]
& XSLT --- Mike Trotman wrote:
> I'm using XML::LibXML 1.58 and had the same problem
with segfaulting
> that seemed to be from freeing variables as they
went out of scope.
>
> I tracked it down (following some comments in this
list) to the fact
> that my function was returning a nodelist
> (or at least multiple nodes).
> If I returned a single node then everything worked
fine.
I'm also using v1.58 and, now that I think of it, my
bug (at least one of them) was the same: single node
works fine, NodeList faults.
> I was also slightly confused by your description of
what you're trying
> to do.
Perhaps it may help to discuss the project I'm working
on. It's a web development framework that focuses on
building sites rather than applications. Broadly
speaking you have a bunch of content in XML, a bunch
of templates in XSLT, and a special XML file that
contains site metadata. Perl and Paperboy RSS (a C
program that provides an ultra-simple front-end to
libxml2/libxslt) are used as glue to apply the XSLT to
the XML in the right manner.
The problem that's shown up on my plate is this (I
don't recall which files were X/Y/Z in my previous
example, so I'll use different ones):
-- In file A you have the content of a weblog in some
<blog> doctype-- personal blog, site updates,
whatever.
-- In file B you have the content of a generic webpage
in some <webpage> doctype.
-- Say you want to have a box in your outputted xhtml
showing the latest post(s) from A in the page that's
described/defined in B.
-- This could be a sidebar of the latest updates, so
all <webpage> s would have it, and hence would best be
dealt with in the xslt file for transforming B into
xhtml.
-- Or it could be a lone thing (like the most recent
post shown on http://collab.freegeek.org/~wren/) and
so you'd want to say to do it in B rather than having
every one of these one-time exceptions listed in your
xslt for all <webpage> files.
The first case (sidebar, defined in xslt) I'm pretty
comfortable with handling. The problem is how to deal
with the second case (defined in xml B)? The solution
should be general, hence my (overly) general
description before. I've no problem in doing the
transformations in multiple passes (once to resolve
<?embedded-xslt ...?> or the like, and then once for
your normal transformation of B. Though for
performance issues I'd like to avoid this if
reasonably possible.
The embedded xslt would be like what normally comes
under <xsl:template> . So instead of having:
<xsl:template match="foo">
<xsl:value-of select="document(foo)/foo" />
</xsl:template>
...in your xslt somewhere, instead you would have:
<?embedded-xslt
<xsl:value-of select="document(foo)/foo" />
?>
...or...
<embedded-xslt>
<xsl:value-of select="document(foo)/foo" />
</embedded-xslt>
...in your xml file B. So it's sort of an ad hoc "when
you get here, pretend this is what the xslt file is
telling you to do" thing. (Which I suppose could also
be used if you have any novel one-of-a-kind
transformations you want to do, even if they don't
access other xml databases.) I've no particular
preference for using an element or a processing
instruction, but the PI seems more appropriate here.
I'm not sure how/whether it should deal with templates
defined in A's normal xslt file. It seems that it
would be quite difficult to access them without doing
a whole lot of parsing and reparsing of files. And you
may want to deal with nodes of a given name
differently in B than they would normally be dealt
with in A. Which would both be a good arguments for
forbidding accessing them. For project's current test
implementation, I have an xslt of common stylistic
transformations that gets imported to xslts for
specific doctypes like <blog> et al. If the embedded
xslt is dealt with before the normal xsl
transformation, then these common templates could be
used normally.
Does that help things make any more sense? (Any new
decisions that I'm crazy for trying this approach? ;)
Live well,
~wren
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Wren Argetlahm
Mike Trotman
Wren Argetlahm
|