Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 08:47 AM
Eshrath
Guest
 
Posts: n/a
Default Sending XML Content (with < >) as value of an attributes to Object tag in HTML

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.
  #2  
Old July 20th, 2005, 08:47 AM
Marrow
Guest
 
Posts: n/a
Default Re: Sending XML Content (with < >) as value of an attributes to Object tag in HTML

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:output 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:otherwise>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


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


"Eshrath" <eshrath@gmail.com> wrote in message
news:4fb5e70e.0410201311.70daf21@posting.google.co m...[color=blue]
> 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.[/color]


  #3  
Old July 20th, 2005, 08:47 AM
Marrow
Guest
 
Posts: n/a
Default Re: Sending XML Content (with < >) as value of an attributes to Object tag in HTML

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:output 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:otherwise>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


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

"Eshrath" <eshrath@gmail.com> wrote in message
news:4fb5e70e.0410201311.70daf21@posting.google.co m...[color=blue]
> 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.[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles