Allowing mis-matched tags (non-well-formed XML)

N

nadahalli

Hello,

I have an XSL file that has something like this:

<xsl:if test-condition1>
<body attribute1 attribute2>
</xsl:if>
<xsl:if test-condition2>
<body attribute3 attribute4>
</xsl:if>
[[[BODY CONTENT]]]
</body>

This fails to compile as this is not a well formed XML file
(mismatched body tag). Is there a simple workaround without
duplicating the entire body contents across both condition bodies.

-woolee_master
 
A

Andy Dingley

Is there a simple workaround without
duplicating the entire body contents across both condition bodies.

You need to keep your XSL source well-formed and valid.

Duplicate the <body> start tag

Use <xsl:attribute name="..." value="..." /> within your tests.

You might even use <xsl:attribute name="..." > before your tests and
then just return the values for these attributes from within the tests
(check the whitespace though). I assume that you#re generating HTML
here and your "attributes" are something like "class" or "title" where
you're using the same attribute each time, but with diffferent values.

Perhaps best of all though is to set up a variable simply and cleanly
beforehand, then use it in the start tag:

<body class="{$classNames}" >
 
N

nadahalli

Yes, my attributes are class, title, and such like.

I had given an instance of a bigger problem I face. My overall problem
is that I want malformed HTML to be output as a result of my XSL
transformation. But the XSL style-sheet doesn't allow it. I tried
stuffing all my malformed HTML into CDATA so that XSL treats it like
data and not XML/HTML. That doesn't work because XALAN later escapes
CDATA and browsers don't render the escaped HTML.

Any help? If I am being too vague, I can mail some XSL snippets.

-woolee_master.
 
J

Johannes Koch

I have an XSL file that has something like this:

<xsl:if test-condition1>
<body attribute1 attribute2>
</xsl:if>
<xsl:if test-condition2>
<body attribute3 attribute4>
</xsl:if>
[[[BODY CONTENT]]]
</body>

Something like:

<body>
<xsl:if test="test-condition1">
<xsl:attribute name="attribute1">...</xsl:attribute>
<xsl:attribute name="attribute2">...</xsl:attribute>
</xsl:if>
<xsl:if test="test-condition2">
<xsl:attribute name="attribute3">...</xsl:attribute>
<xsl:attribute name="attribute4">...</xsl:attribute>
</xsl:if>
[[[BODY CONTENT]]]
</body>
 
J

Joseph Kesselman

is that I want malformed HTML to be output as a result of my XSL
transformation.

If you step outside the assumptions of the XML world, you're going to
have to fight the tools every step of the way.

For example: You could try to achieve this by setting the output to text
rather than HTML. But then you're going to have to hand-construct every
single tag in the output.

Personally, my solution would be to discard and replace whatever tool is
demanding ill-formed files, NOW. Life's too short to spend it working
around broken applications.
 
S

Simon Brooke

in message <[email protected]>,
Yes, my attributes are class, title, and such like.

I had given an instance of a bigger problem I face. My overall problem
is that I want malformed HTML to be output as a result of my XSL
transformation. But the XSL style-sheet doesn't allow it. I tried
stuffing all my malformed HTML into CDATA so that XSL treats it like
data and not XML/HTML. That doesn't work because XALAN later escapes
CDATA and browsers don't render the escaped HTML.

Any help? If I am being too vague, I can mail some XSL snippets.

-woolee_master.

You cannot do this. And it's a good thing that you cannot do this. The
world has much too much malformed HTML already, we don't need any more.

--
(e-mail address removed) (Simon Brooke) http://www.jasmine.org.uk/~simon/
.::;===r==\
/ /___||___\____
//==\- ||- | /__\( MS Windows IS an operating environment.
//____\__||___|_// \|: C++ IS an object oriented programming language.
\__/ ~~~~~~~~~ \__/ Citroen 2cv6 IS a four door family saloon.
 
J

Joe Kesselman

That doesn't work because XALAN later escapes
CDATA and browsers don't render the escaped HTML.

It is possible to tell XSLT that you would prefer the content of some
elements be escaped via <![[CDATA]]> section markup, rather than
character by character. See xsl:eek:utput's cdata-section-elements attribute.

But explicitly relying upon CDATA Sections is a sin and an abomination
before the eyes of the Architects.
 
A

Andy Dingley

My overall problem
is that I want malformed HTML to be output as a result of my XSL
transformation.

No you don't.

You don't need this. There's nothing out there worth using that
requires you to do this. Why do you think you do?

If you mean "I want to generate HTML that isn't well-formed XML", then
that's fine (but isn't "malformed"). Just use

<xsl:eek:utput method="html" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top