将CSS类分配给使用SQL"FOR XML"生成的HTML标签 [英] Assign CSS class to HTML tags generated with SQL 'FOR XML'

查看:44
本文介绍了将CSS类分配给使用SQL"FOR XML"生成的HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用"FOR XML"从SQL获取表行和表数据(带有HTML标记).有没有一种方法可以将CSS类分配给SQL中的html标记?

I am getting table rows and table data (with HTML tags) from SQL using 'FOR XML'. Is there a way I could assign CSS classes to the html tags in SQL?

我现在得到的是:< tr>< td>名称</td>< td>值</td></tr>

SQL查询:

SELECT  (SELECT [Name] as [td] FOR XML PATH(''), type),
        (SELECT [Value] as [td] FOR XML PATH(''), type)
FROM    table
FOR XML PATH('tr')

所需的输出:

< tr class ="test1">< td class ="test2">名称</td>< td class ="test3">值</td></tr>

推荐答案

我知道我在回答自己的问题,认为这可能会对其他人有所帮助.

I know I am answering my own question, thought it may help someone else.

我正在将类作为属性添加到XML节点,这将为我提供所需的输出.

I'm adding class as an attribute to XML nodes which is giving me the desired output.

SELECT  'test1' AS [@class]
    , ( SELECT  'test2' as [@class]
        , (SELECT 'Name' FOR XML PATH(''))
        FOR XML PATH('td'), type)
    ,(SELECT  'test3' as [@class]
        , (SELECT 'Value' FOR XML PATH(''))
        FOR XML PATH('td'), type) 
FOR XML PATH('tr'), type


输出:
< tr class ="test1">< td class ="test2">名称</td>< td class ="test3">值</td></tr>

这篇关于将CSS类分配给使用SQL"FOR XML"生成的HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆