472,128 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,128 software developers and data experts.

Xsl with <br/> problem

Hi,

I am having a small problem, that is driving me nuts.
My application reads some Xml and runs 2 Xsl Transformations to generate
HTML. As soon as my second XSL introduces some <br/tags, the application
crashes with the same error message I would get when writing <brand no
closing tag. To make everything a little stranger, even <br></brseems to
be bad while <lbr/is fine. Ive tried some other tag names and the problem
only appears with br-tags ... any ideas?

Regards,
Chris

Jan 2 '07 #1
4 4187
You forgot to provide your code

Cheers,
Dimitre Novatchev
"Christofer Dutz" <ch*************@univativ.dewrote in message
news:00******************@fe62.usenetserver.com...
Hi,

I am having a small problem, that is driving me nuts.
My application reads some Xml and runs 2 Xsl Transformations to generate
HTML. As soon as my second XSL introduces some <br/tags, the application
crashes with the same error message I would get when writing <brand no
closing tag. To make everything a little stranger, even <br></brseems to
be bad while <lbr/is fine. Ive tried some other tag names and the
problem only appears with br-tags ... any ideas?

Regards,
Chris


Jan 2 '07 #2
Oh gee ... I thought this might be a stadard issue and I didn't need to.
Here is my Transformer Component:

using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.XPath;
using System.Xml.Xsl;

/// <summary>
/// Zusammenfassungsbeschreibung für Class1
/// </summary>
namespace Transformers
{
public class XslTransformer : AbstractTransformer
{
protected XslCompiledTransform myXslTrans;

public XslTransformer()
{
}

override public void Setup(HttpRequest request, HttpResponse
response, SortedList parameters)
{
String templateUri = (String) parameters["src"];

// Setup a cleanup transformation, since the sql server sends us
really crap code
myXslTrans = new XslCompiledTransform();
myXslTrans.Load(templateUri);
}

override public void Destroy()
{
myXslTrans = null;
}

public override XPathDocument Produce()
{
XPathDocument inputDoc = this.producer.Produce();

// Write the result to an in-memory temorary document
MemoryStream memStream = new MemoryStream();

// Execute the transformation
myXslTrans.Transform(inputDoc, null, memStream);

// Reset the memory stream so the "read-head" points to
// the beginning of the document
memStream.Position = 0;
// Create a new Dom Object from the byte junk in the memStream
XPathDocument outputDoc = new XPathDocument(memStream);
return outputDoc;
}
}
}

And here the Xsl, but I don't really understand why "<br/>" doesn't work and
"<lbr/>" does. No matter where I have a <br/tag ... execution fails when
creating the new XPathDocument outputDoc:

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/profil">

<html>

<body>

<h1>Mitarbeiter-Profil</h1>

<table>

<tr>

<td>

<image src="http://192.168.1.102/Univativ/MA_Fotos/MA_{person/id}.jpg"
height="100"/>

</td>

<td>

<h2>

<xsl:if test="person/akademischer-titel">

<xsl:value-of select="person/akademischer-titel"/>

<xsl:text disable-output-escaping="yes"</xsl:text>

</xsl:if>

<xsl:value-of select="person/vorname"/>

<xsl:text disable-output-escaping="yes"</xsl:text>

<xsl:value-of select="person/nachname"/>

</h2>geboren am : <xsl:value-of select="person/geburtstag"/>

</td>

</tr>

<xsl:if test="/profil/ausbildung/studium">

<tr>

<td>

<h3>Studium</h3>

</td>

<td>

<xsl:for-each select="/profil/ausbildung/studium/studiengaenge/studiengang">

<b><xsl:choose>

<xsl:when test="(string-length(@von) = 0) and (string-length(@bis) = 0)"/>

<xsl:when test="(string-length(@von) = 0)">bis <xsl:value-of
select="@bis"/>: </xsl:when>

<xsl:when test="(string-length(@bis) = 0)">seit <xsl:value-of
select="@von"/>: </xsl:when>

<xsl:otherwise><xsl:value-of select="@von"/- <xsl:value-of
select="@bis"/>: </xsl:otherwise>

</xsl:choose><xsl:value-of select="@bezeihnung"/>, <xsl:value-of
select="@universitaet"/>

</b><xsl:value-of select="@abschluss"/>

</xsl:for-each>

</td>

</tr>

</xsl:if>

<xsl:if test="/profil/ausbildung/lehre">

<tr>

<td>

<h3>Ausbildungen</h3>

</td>

<td>

<b>Ausbildungen</b>

</td>

</tr>

</xsl:if>

<xsl:if test="/profil/praxiserfahrung/projekt">

<tr>

<td>

<h3>Praxisreferenzen</h3>

</td>

<td>

<xsl:for-each select="/profil/praxiserfahrung/projekt">

<b>

<xsl:choose>

<xsl:when test="(string-length(@von) &gt; 0) and (string-length(@bis) &gt;
0)">

<xsl:value-of select="@von"/- <xsl:value-of select="@bis"/>

</xsl:when>

<xsl:when test="(string-length(@von) &gt; 0)">

seit <xsl:value-of select="@von"/>

</xsl:when>

<xsl:when test="(string-length(@bis) &gt; 0)">

bis <xsl:value-of select="@bis"/>

</xsl:when>

</xsl:choose>:<xsl:value-of select="@firma"/>, <xsl:value-of select="@ort"/>

</b>

<br/>

<xsl:value-of select="@titel"/>

<xsl:if test="position() != last()">

<br/>

<lbr/>

<lbr/>

</xsl:if>

</xsl:for-each>

</td>

</tr>

</xsl:if>

<tr>

<td>

<h3>Kenntnisse</h3>

</td>

<td>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Hardware']">

<b>Hardware</b>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Hardware' and @auspraegung = 3]">

sehr gut: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Hardware' and @auspraegung = 3]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Hardware' and @auspraegung = 2]">

gut: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Hardware' and @auspraegung = 2]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Hardware' and @auspraegung = 1]">

Grundlagen: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Hardware' and @auspraegung = 1]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Betriebssysteme']">

<b>Betriebssysteme</b>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Betriebssysteme' and @auspraegung = 3]">

sehr gut: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Betriebssysteme' and @auspraegung = 3]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Betriebssysteme' and @auspraegung = 2]">

gut: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Betriebssysteme' and @auspraegung = 2]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Betriebssysteme' and @auspraegung = 1]">

Grundlagen: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Betriebssysteme' and @auspraegung = 1]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Office-Anwendungen']">

<b>Office-Anwendungen</b>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Office-Anwendungen' and @auspraegung = 3]">

sehr gut: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Office-Anwendungen' and @auspraegung = 3]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Office-Anwendungen' and @auspraegung = 2]">

gut: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Office-Anwendungen' and @auspraegung = 2]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Office-Anwendungen' and @auspraegung = 1]">

Grundlagen: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Office-Anwendungen' and @auspraegung = 1]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Datenbanken']">

<b>Datenbanken</b>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Datenbanken' and @auspraegung = 3]">

sehr gut: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Datenbanken' and @auspraegung = 3]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Datenbanken' and @auspraegung = 2]">

gut: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Datenbanken' and @auspraegung = 2]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<xsl:if test="/profil/faehigkeiten/faehigkeit[@bereich = 'EDV-Kenntnisse'
and @gruppe = 'Datenbanken' and @auspraegung = 1]">

Grundlagen: <xsl:for-each select="/profil/faehigkeiten/faehigkeit[@bereich =
'EDV-Kenntnisse' and @gruppe = 'Datenbanken' and @auspraegung = 1]">

<xsl:value-of select="@bezeichnung"/>

</xsl:for-each>

<lbr/>

</xsl:if>

<lbr/>

</xsl:if>

</td>

</tr>

<xsl:if test="/profil/person/sprachen/sprache">

<tr>

<td>

<h3>Sprachen</h3>

</td>

<td>

<xsl:for-each select="/profil/person/sprachen/sprache">

<xsl:value-of select="@bezeichnung"/><!-- - <xsl:choose>

<xsl:when test="@sprachbeherschungs-grad = '1'">schlecht</xsl:when>

<xsl:when test="@sprachbeherschungs-grad = '2'">gut</xsl:when>

<xsl:when test="@sprachbeherschungs-grad = '3'">sehr gut</xsl:when>

</xsl:choose>-->

<lbr/>

</xsl:for-each>

</td>

</tr>

</xsl:if>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>
Chris
"Dimitre Novatchev" <di******@tpg.com.auschrieb im Newsbeitrag
news:45***********************@authen.yellow.readf reenews.net...
You forgot to provide your code

Cheers,
Dimitre Novatchev
"Christofer Dutz" <ch*************@univativ.dewrote in message
news:00******************@fe62.usenetserver.com...
>Hi,

I am having a small problem, that is driving me nuts.
My application reads some Xml and runs 2 Xsl Transformations to generate
HTML. As soon as my second XSL introduces some <br/tags, the
application crashes with the same error message I would get when writing
<brand no closing tag. To make everything a little stranger, even
<br></brseems to be bad while <lbr/is fine. Ive tried some other tag
names and the problem only appears with br-tags ... any ideas?

Regards,
Chris




Jan 2 '07 #3
Christofer Dutz wrote:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/profil">

<html>
Is that html element the root of your result tree? Then the XSLT
processor switches to output method html and serializes the result tree
as HTML for known HTML elements like the 'br' element so an empty
element will be serialized the HTML way which is <br>. 'lbr' is not a
known HTML element so it will be serialized the normal way as <lbr/or
<lbr></lbr>.

Thus if you want to have XML output even with a root element of 'html'
in the result tree then you need to specify
<xsl:output method="xml"/>
in the stylesheet.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 2 '07 #4
That did the trick ...
Geee ... I hate it when software starts acting too intelligent :(
html was indeed the root of my output document, but it's only an
intermediate format, seting the output format worked fine :) Thanks ;)

Chris

"Martin Honnen" <ma*******@yahoo.deschrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP06.phx.gbl...
Christofer Dutz wrote:
><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/profil">

<html>

Is that html element the root of your result tree? Then the XSLT processor
switches to output method html and serializes the result tree as HTML for
known HTML elements like the 'br' element so an empty element will be
serialized the HTML way which is <br>. 'lbr' is not a known HTML element
so it will be serialized the normal way as <lbr/or <lbr></lbr>.

Thus if you want to have XML output even with a root element of 'html' in
the result tree then you need to specify
<xsl:output method="xml"/>
in the stylesheet.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Jan 3 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by noor.rahman | last post: by
9 posts views Thread by Wayne | last post: by
3 posts views Thread by ajay2552 | last post: by
7 posts views Thread by Nathan Sokalski | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.