
Originally Posted by
bbolte
i didn't even think about doing that. it almost doesn't look well formed. hmmmm. will have to investigate some. thanks vinnie...
The XML is well-formed, but it may or may not validate depending on what you have in your DTD or schema (if you have one at all, which you should
). If you have a DTD/schema and the <a> element isn't in it, your XML file won't validate.
One thing you should know with this approach though is that the <a> element can be treated just like any other element/node in your XML file (meaning it can be accessed by XPath, etc). If you don't want this to happen, wrap the contents of your <article> element in a CDATA section, like so:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="content.xsl" type="text/xsl"?>
<content xmlns:html="http://www.w3.org/1999/xhtml">
<article>
<![CDATA[
This is content with a link, <a href="http://www.mylink.com">click here</a>.
]]>
</article>
</content>
If you wrap it in a CDATA section you have to alter the stylesheet a little bit and use value-of instead of copy-of (since you don't want a copy of everything, you just want the value of the CDATA section). You also have to disable output escaping so the angle brackets of the links don't get turned into the encoded equivalents (& gt; and & lt; ) Here's the stylesheet that worked for me:
HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" version="4.01" encoding="utf-8" />
<xsl:template match="/">
<html>
<head>
<title>Transformation!</title>
</head>
<body>
<p><xsl:value-of disable-output-escaping="yes" select="content/article" /></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I think this method will work best actually, as opposed to the previous method, because it keeps your article content from getting mixed up in your XML data, and if you decide you want to use a DTD or Schema in the future you don't have to add any HTML elements into it. Hope this helps!
Bookmarks