[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Serializing external XML documents


Subject: Re: [xsl] Serializing external XML documents
From: Pedro Pastor <pps@xxxxx>
Date: Wed, 10 Oct 2001 12:45:11 +0200

Thank you very much for you concise and clear answer, Jeni.

Asking to your question: Yes there are Tamino HTTP functions for querying
(XPath), deleting documents, updating and a set of DB administration
functions. Anyway, I do not dare to give any lecturing on Tamino as we
count in this list with the "presence" of Mr. Michael Kay.

Imagine all the things we can do if we could implement a pure XSLT
transactional application accessing a DB using HTTP. Consider different
points: XSLT over Cocoon for dynamic application generation, the proper
XSLT programs (o meta-XSLT stylesheets) could be stored in the database,
dynamic code generation (XML Schema and XQueryX), talking SOAP or
WebServices (WSDL) from XSLT, etc.

But coming back to your "side effects" complaining, I agree with you, and
I would like to know if there is anything foreseen on this topic for XSLT
2.0. If we would like to use XSLT as pure XML processing, a specific HTTP
protocol access function from an XSLT program is desirable (if not
compulsory).

Pedro Pastor
University of Alicante (Spain)


Jeni Tennison wrote:

> Hi Pedro,
>
> > 1) I am using "document()" function (maybe abusing of it) to talk
> > HTTP with an external application: Tamino DB.
> >
> > Question: Is there any other XSLT standard way of talking HTTP from
> > inside a stylesheet ?
>
> No. I'm interested about what you're doing here, because it
> illustrates that xsl:message isn't the only thing that makes XSLT fall
> short of the "no side-effects" ideal that's often touted as one of its
> advantages. Presumably the _process URL causes information to be
> inserted in the database; do you also have a document() function
> *reading* from the same database?
>
> > 2) One of the possible calls to Tamino is a "_process" function for
> > content updating purposes. The syntax for this function is:
> >
> > DB-URL?_process=<XML object> (XML object stands for a text
> > serialized XML fragment)
> >
> > Question: What is the most practical way of reading an external
> > XML-file with the desired target XML information and serialize it as
> > non-escaped XML markup text and insert it into the "document()"
> > function to perform the HTTP call ?
>
> If you're using MSXML, then you're lucky because you can create a
> function that uses MSXML's own serialisation routines, something like:
>
> <msxsl:script language="javascript" implements-prefix="my">
>   function serialize(nodeSet) {
>     return nodeSet.item(0).xml;
>   }
> </msxsl:script>
>
> which you can then include in your document() call with:
>
>   document(concat('DB-URL?_process=', my:serialize($source)))
>
> If you're not using MSXML, then you need to create a string
> serialisation with a set of templates, e.g. for elements you need
> something along the lines of:
>
> <xsl:template match="*" mode="serialize">
>   <xsl:text />&lt;<xsl:value-of select="name()" />
>   <xsl:apply-templates select="@*" mode="serialize" />
>   <xsl:choose>
>     <xsl:when test="node()">
>       <xsl:text>></xsl:text>
>       <xsl:apply-templates mode="serialize" />
>       <xsl:value-of select="concat('&lt;/', name(), '>')" />
>     </xsl:when>
>   </xsl:choose>
> </xsl:template>
>
> For attributes you need something like:
>
> <xsl:template match="@*">
>   <xsl:value-of select="concat(' ', name(), '=&quot;')" />
>   <xsl:call-template name="escapeXML">
>     <xsl:with-param name="string" select="." />
>   </xsl:call-template>
>   <xsl:text>"</xsl:text>
> </xsl:template>
>
> where 'escapeXML' is a template that takes a string and replaces all
> '&' with '&amp;', '<' with '&lt;' and so on. You need a similar thing
> for text nodes:
>
> <xsl:template match="text()">
>   <xsl:call-template name="escapeXML">
>     <xsl:with-param name="string" select="." />
>   </xsl:call-template>
> </xsl:template>
>
> These are the simple templates - if you use namespaces, you also have
> to worry about those within the template for serialising the elements;
> if you have comments and processing instructions that you want to keep
> then you have to have templates to serialise those as well, of course.
>
> I hope that helps,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.com/
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords