all groups > dotnet xml > january 2007 >
You're in the

dotnet xml

group:

Xsl with <br/> problem



Re: Xsl with <br/> problem Dimitre Novatchev
1/2/2007 6:32:22 AM
dotnet xml: You forgot to provide your code

Cheers,
Dimitre Novatchev


[quoted text, click to view]

Xsl with <br/> problem Christofer Dutz
1/2/2007 3:30:18 PM
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 <br> and no
closing tag. To make everything a little stranger, even <br></br> seems 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


Re: Xsl with <br/> problem Christofer Dutz
1/2/2007 3:44:16 PM
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 =
Re: Xsl with <br/> problem Martin Honnen
1/2/2007 4:22:31 PM
[quoted text, click to view]

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
Re: Xsl with <br/> problem Christofer Dutz
1/3/2007 8:32:21 AM
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" <mahotrash@yahoo.de> schrieb im Newsbeitrag
news:%23MmLUHoLHHA.1008@TK2MSFTNGP06.phx.gbl...
[quoted text, click to view]


AddThis Social Bookmark Button