Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

XML anyone?

Featured Replies

Hello,

 

I have created an XML document which has an element called <content> which contains XHTML.

 

Whn I view the output in Firefox, the XHTML tags are not being rendered. The text is, but not the XHTML. I have used XSL to format the document and I can't put the XML there since the XHTML could change.

 

So for example in the XSL I have:

 

<div id="header">
<xsl:value-of select="site/header/content"/>
</div>

and the XML has:

 

<content>
<h2>News And Events</h2>
<p>Some of our latest news here...</p>
</content>

 

Now I kinda understand this since my xml document hasn't defined anything for any xhtml elements. I don't want to since I want the browser to just render these as normal. I have tried a few things in my xsl like:

 

<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="iso-8859-1"/>

 

and using:

 

<xsl:value-of select="content" disable-output-escaping="yes"/>

 

but I either get the tags rendered as entities (i.e. < etc) or no tags at all?

 

Has anybody had any experience of doing something similar?

 

Not sure if I have provided all the info here so please let me know.

 

Thanks in advance,

 

Tim

<div id="header">
<xsl:value-of select="site/header/content"/>
</div>

Eeek! :o <xsl:value-of> produces a text node in the output. You want to copy the source tree into the output. So I think you really mean to use <xsl:copy-of>:

 

<div id="header">
<xsl:copy-of select="site/header/content"/>
</div>

Does that sort it?

  • Author
Eeek! :o <xsl:value-of> produces a text node in the output. You want to copy the source tree into the output. So I think you really mean to use <xsl:copy-of>:

 

<div id="header">
<xsl:copy-of select="site/header/content"/>
</div>

Does that sort it?

 

Great! Thank you - I think this has done it! I am kinda testing out this doc (and finally getting round to properly learning XML) and gonna use Java to parse it fully into XHTML (I hope!) for output.

 

Many Thanks again - especially for the quick response!

Great! Thank you - I think this has done it! I am kinda testing out this doc (and finally getting round to properly learning XML) and gonna use Java to parse it fully into XHTML (I hope!) for output.

That's something I've done myself many times before! XSLT is very useful and worth knowing... using it you can convert an XML data tree into SVG graphics, or XSL Formatting Objects which can easily be turned into a PDF, DOC, and many other formats (e.g. via Apache FOP). Good luck!

  • Author
That's something I've done myself many times before! XSLT is very useful and worth knowing... using it you can convert an XML data tree into SVG graphics, or XSL Formatting Objects which can easily be turned into a PDF, DOC, and many other formats (e.g. via Apache FOP). Good luck!

 

Just another question to pick your brains while you're about. When I look at the source of the document, I get the XML. I understand that since the browser is just using the XSL to format it and I can control how it is formatted (via xsl:output) but is there a way of ensuring that the source is "permanently changed" into XHTML? I'm probably asking a dumb question since I am actually not supplying XHTML. Just thinking aloud!

I think what you're asking is: "is there a way to get the XML into XHTML before it gets to the browser?" Generally, sending the user an XSL sheet is a bad idea (taking into account browser inconsistencies and all). So if you can send them XHTML directly, that's far better.

 

And yes you can, if you're using some kind of server-side code. You mentioned Java, that'd certainly do it (see the javax.xml.transform classes). Also there's PHP XSLT for PHP servers, and Xalan C++ for native programs.

 

Basically, run your source+XSL through a program like that and it'll generate the resulting XHTML, which you can save as a file or serve as an HTTP response. Indeed, this is a lot more efficient to do this once and save the XHTML than having to apply the transform every time, if it's a "static" kind of page. Alternatively, if it's dynamic data, doing it on the server-side for each request (using the libraries I mentioned above) is preferable to letting the user's browser take care of it. Caching dynamically generated pages may also help you---e.g. if each customer has a different view, but it doesn't change often/at all, then caching the XHTML page so it can be served as static data on each request is going to speed up your application.

 

Did I understand/answer your question?

  • Author

Cool - thought that might be the case.

 

I'm using a JSF/JSP/Facelets kind of set up so am gonna transform into XHTML with some other JSF kinda stuff in there too. (I keep falling in and out of love with JSF!)

 

Thank you once again!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.