Re: [xslt] XSLT-problems



On Tue, Apr 17, 2001 at 10:21:53PM +0200, Gerhard Dieringer wrote:
> Hi everbody,
> 
> I have the following problems with libxml2-2.3.6 and libxslt-0.7.0:
> 
> I create a DOM-tree with the functions xmlNewChild and xmlSetProp. Then
> I
> render the DOM-tree with xmlDocDumpMemory into a Buffer and write it to
> a file. In the last step I use xsltproc and tranlate the XML document
> into a text (SQL). This solution works, but I don't like it, because
> it would be much better to avoid the XML file and just use
> xsltApplyStylesheet
> to produce a result DOM-tree and render it with xmlDocDumpMemory. 

   I don't see what prevents you from doing this ? Use
   xsltStylesheetPtr xsltParseStylesheetDoc(xmlDocPtr doc)
on the memory DOM you built.

> The second, not correctly working solution has several problems:
> 
> 1.) The XPath function id(...) does not work, so I have to use the much
> slower expression //*[ id=   ]
> This seems to be an XML, not XSLT problem.

  yes to work you need to at least read the DTD.

> I assume, that the DTD is only used in the first, working case, where
> the
> XML file is read by xsltproc and not in the second case, where the tree
> is constructed an then processed.

  I'm not sure I understand. The DTD processing must be done
on the processed document, not on the stylesheet.
  If your document don't have a DOCTYPE libxml can't "invent" the IDs
for you. The fact that an attibute is named "id" does not mean it is
of type ID, only a DTD (and Schemas in the future) can provide this
kind of type informations.

> 2.) Although I have a 
> method="text" and omit-xml-declaration="yes" 
> in my xsl:output, the generated file starts with 
> <?xml version="1.0" encoding="iso-8859-1"?>
> which I don't want in my SQL output

  Hum, strange, the tests/REC2/vrml.xsl test exercise this:

orchis:~/XSLT/tests/REC2 -> grep xsl:output vrml.xsl
<xsl:output method="text" encoding="UTF-8" media-type="model/vrml"/>  
orchis:~/XSLT/tests/REC2 -> more vrml.xml 
#VRML V2.0 utf8 
 
   and the output definitely is text not XMLish, please provide a 
test case with the XSL and XML input because I can't reproduce it here.

> 3.) The expressions &lt; and &gt; are not translated to < and >.
> 
> The function xsltSaveResultToFilename, that is used by xsltproc
> seems to solve the problems 2 and 3, but it writes the output to
> a file and not into a buffer.

  Hum, if you use one of the predefined libxml dump routine, then
of course 2/ and 3/ appears since you ask to save an XML file.

  Use xsltSaveResultTo, you can create a memory based xmlOutputBufferPtr
with xmlAllocOutputBuffer(NULL), the output will be in
  out_buff->buffer->content and the len will be out_buff->conv->use,
release it with xmlOutputBufferClose(out_buff)

Daniel

-- 
Daniel Veillard      | Red Hat Network http://redhat.com/products/network/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/




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