Sending XML Content (with < >) as value of an attributes to Object tag in HTML

E

Eshrath

Hi,

What I am trying to do:
=======================

I need to form a table in html using the xsl but the table that is
formed is quite long and cannot be viewed in our application. So we
are writing one object in C# which will take the entire table tag
contents and renders. Ie., we need to pass "<table>…………
<thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
the object using Object tag.

So I have written the xsl as

<object classid="………..">
<xsl:attribute name="HTMLContent">
<xsl:apply-templates select="tgroup"/>
</xsl:attribute>
</object>

Here the HTMLContent is an attribute of the object which will be
interpreted by the C# objeect class aptly. "tgroup" template would
give the entire table content ( "<table>………… <thead>……</thead>.
<tr>.<td> <td>..<tr>.<td> <td> </table>" ).

This XSL should be transformed as

<object classid="……." HTMLContent="<table>………… <thead>……</thead>.
<tr>.<td> <td>..<tr>.<td> <td> </table>">

But the table tag value is going as blank to the HTMLContent
attribute.
i.e,

<object classid="……." HTMLContent="">

But if I give some thing like

<object classid="………..">
<xsl:attribute name="HTMLContent">
Sample
</xsl:attribute>
</object>

The XSL transforms as

<object classid="……." HTMLContent="Sample">
</object>

I really don't understand why the table content is not getting in to
the HTMLContent attribute of Object tag. Is there a way where I can do
like this.

I am struck up in this for a long time. Please help me out.

Thanks and Regards,
-Eshrath.
 
M

Marrow

Hi,

Not sure trying to put markup inside an attribute is ever the best idea?
I've never used the <object> much - are you sure you can't put the markup as
the content in some way (maybe namespaced?).

But anyway, to put markup into an attribute using XSL you will need to do
your own escaping of the tags, e.g.

== XML ==============================
<?xml version="1.0"?>
<tgroup>
<table border="1">
<!-- comment -->
<?pi something?>
<thead>hd</thead>
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</tgroup>
== end of XML =======================

== XSL ==============================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<html>
<body>
<object classid=".....">
<xsl:attribute name="HTMLContent">
<xsl:apply-templates select="tgroup" mode="esc-start"/>
</xsl:attribute>
</object>
</body>
</html>
</xsl:template>

<xsl:template match="*" mode="esc-start">
<xsl:apply-templates mode="esced"/>
</xsl:template>

<xsl:template match="*" mode="esced">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="esced"/>
<xsl:text>&lt/;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:template>

<xsl:template match="@*" mode="esced">
<xsl:text> </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:template>

<xsl:template match="comment()" mode="esced">
<xsl:text>&lt;!--</xsl:text>
<xsl:value-of select="."/>
<xsl:text>--&gt;</xsl:text>
</xsl:template>

<xsl:template match="processing-instruction()" mode="esced">
<xsl:text>&lt;?</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
<xsl:text>?&gt;</xsl:text>
</xsl:template>

</xsl:stylesheet>
== end of XSL =======================

You could etend this further with a template (in mode "esced") that looked
for HTML tags that didn't require closing properly (i.e. <br>, <hr>, etc.),
e.g. adding the template...

<xsl:template match="*[contains('|br|hr|',concat('|',
translate(name(),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz'),'|'))]" mode="esced">
<xsl:choose>
<xsl:when test="node()">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="esced"/>
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:when>
<xsl:eek:therwise>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>


HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
 
M

Marrow

Hi,

Not sure trying to put markup inside an attribute is ever the best idea?
I've never used the <object> much - are you sure you can't put the markup as
the content in some way (maybe namespaced?).

But anyway, to put markup into an attribute using XSL you will need to do
your own escaping of the tags, e.g.

== XML ==============================
<?xml version="1.0"?>
<tgroup>
<table border="1">
<!-- comment -->
<?pi something?>
<thead>hd</thead>
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</tgroup>
== end of XML =======================

== XSL ==============================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="html"/>
<xsl:template match="/">
<html>
<body>
<object classid=".....">
<xsl:attribute name="HTMLContent">
<xsl:apply-templates select="tgroup" mode="esc-start"/>
</xsl:attribute>
</object>
</body>
</html>
</xsl:template>

<xsl:template match="*" mode="esc-start">
<xsl:apply-templates mode="esced"/>
</xsl:template>

<xsl:template match="*" mode="esced">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="esced"/>
<xsl:text>&lt/;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:template>

<xsl:template match="@*" mode="esced">
<xsl:text> </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:template>

<xsl:template match="comment()" mode="esced">
<xsl:text>&lt;!--</xsl:text>
<xsl:value-of select="."/>
<xsl:text>--&gt;</xsl:text>
</xsl:template>

<xsl:template match="processing-instruction()" mode="esced">
<xsl:text>&lt;?</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
<xsl:text>?&gt;</xsl:text>
</xsl:template>

</xsl:stylesheet>
== end of XSL =======================

You could etend this further with a template (in mode "esced") that looked
for HTML tags that didn't require closing properly (i.e. <br>, <hr>, etc.),
e.g. adding the template...

<xsl:template match="*[contains('|br|hr|',concat('|',
translate(name(),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz'),'|'))]" mode="esced">
<xsl:choose>
<xsl:when test="node()">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="esced"/>
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:when>
<xsl:eek:therwise>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>


HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top