سؤال

I have a collection of xml files within eXist-db (1.4.2).

They are all structured similarly to this:

<magazine>
    <issue.number>22</issue.number>
    <article>
        <title>first article</title>
        <subject>James</subject>
    </article>
    <article>
        <title>second article</title>
        <subject>Billy</subject>
    </article>
</magazine>

I wish to query all files via the REST api: http://localhost:8080/exist/rest/db/folder/test.xq

The result is:

<entries>
    <entry> 
        <name>James</name>
    </entry>
    <entry>
        <name>Billy</name>
    </entry>
<entries>

I want to be able to style the xquery output. I have attempeted to do so by referencing a stylesheet at the start of my .xq. So now test.xq begins with <xml> <?xml-stylesheet type="application/xml" href="test.xsl"?>

Whatever I change I cannot get anything more than a string of text, with no style at all.

Where am I going wrong?

Do I just have a badly written stylesheet? Or am I wrong thinking that I can use an .xsl within an .xq?

هل كانت مفيدة؟

المحلول

To have the xslt-transformation done by the browser, the stylesheet processing instruction should appear before the first XML element (http://www.w3.org/TR/xml-stylesheet/) of the document;

It is possible to add the Processing Instruction by constructing it the following way:

processing-instruction xml-stylesheet {'type="application/xml"','href="test.xsl"'},
<myxml/>

The alternative is to use the transform() functions to do the transformation on the server side:

http://exist-db.org/exist/apps/doc/xsl-transform.xml

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top