Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert external file content as HTML through XSLT

Tags:

java

html

xml

xslt

i'm a little stucked with some XSLT issue.

I have some simple xml-files and the following stylesheet:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:param name="linked_content"/>

<xsl:template match="/">
    <html>
        <head>
            <title>Chapter summary</title>
        </head>
        <body BGCOLOR="white">
            <xsl:value-of select="$linked_content"></xsl:value-of>
        </body>
    </html>             
</xsl:template>

</xsl:stylesheet>

The linked_content comes from a simple text file (e.g. summary.txt):

<p>
Consider this as a simple summary ^^
</p>

<h3>Part One</h3>

Now my question: How can i insert the HTML-Code from the text file as HTML code into the resulting html file. I know, the code above wont work, since i only get &gt, &lt in the resulting inserted text.

I'm not stuck to submit the content through a parameter. If their's a way to read the textfile from within the stylesheet, that would great!

Anyone an idea?

EDIT: Still stuck here. I tried a workaround reading the text file in java and setting the content as a parameter to the stylesheet. Sadly the

  • <
  • >

signs are being translated in the process to &lt and &gt ... thus, the html code is screwed. Is there a chance to force the stylesheet not to transform them?

Thx!

like image 762
Gruber Avatar asked May 12 '11 10:05

Gruber


2 Answers

Are your html files well-formed?

You can try using 'copy-of' in your xsl.

<p><xsl:copy-of select="document('yourHtmlDoc.html')"/></p>

If you need specific items out of your html file, you can even set a path, given that your html is well-formed.

<xsl:copy-of select="document('yourHtmlDoc.html')/tagsNeeded"/>
like image 131
Jeff Avatar answered Sep 20 '22 17:09

Jeff


You can use unparsed-text() function which can read external file in. Or if you know that the external file is a valid xml, you can use document() function as well. Both XSLT 2.0 functions however - i think.

like image 35
d-live Avatar answered Sep 20 '22 17:09

d-live