本文介紹了使用 xquery 轉(zhuǎn)換為 html?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時(shí)送ChatGPT賬號..
我有以下數(shù)據(jù)庫電子郵件的 T-Sql.
I have the following T-Sql for database email.
-- create proc TableToHtml @table varchar(max) as
declare @table varchar(max) = '(select 1 a, ''one'' b union all select 2, ''two'') t '
declare @sql varchar(max) = '
declare @xml xml = (
select * from ' + @table + '
for xml path(''tr''), root(''table'')
);
select @xml'
declare @tmp table (x xml)
insert into @tmp exec(@sql)
declare @x xml = (select x from @tmp)
select @x
然后它返回
<table>
<tr>
<a>1</a>
<b>one</b>
</tr>
<tr>
<a>2</a>
<b>two</b>
</tr>
</table>
是否可以編寫 xquery 讓它返回以下 html?
Is it possible to write the xquery to let it returns the following html?
<table>
<tr>
<th>a</th>
<th>b</th>
</tr>
<tr>
<td>1</td>
<td>one</td>
</tr>
<tr>
<td>2</td>
<td>two</td>
</tr>
</table>
推薦答案
我想出了一個(gè)更少黑客攻擊的方案.唯一的問題是如果值為空,它將創(chuàng)建
而不是
.將電子郵件發(fā)送到某些舊 Outlook 客戶端時(shí)會(huì)導(dǎo)致一些布局問題.
I figured out a less hacking one. The only problem is it will create <td />
instead of <td></td>
if the value is null. It will cause some layout issue when the email is sent to some old Outlook clients.
declare @table varchar(max) = '(select 1 a, ''one'' b union all select 2, ''two'') t '
declare @sql varchar(max) = '
declare @xml xml = (
select * from ' + @table + '
for xml path(''tr''), root(''table'')
);
select @xml'
declare @tmp table (x xml)
insert into @tmp exec(@sql)
declare @x xml = (select x from @tmp)
select @x.query('<body>
<table>
<tr>
{for $c in /table/tr[1]/* return element th { local-name($c) } }
</tr>
{
for $r in /table/*
return element tr { for $c in $r/* return element td { data($c) } }
}
</table>
</body>')
這篇關(guān)于使用 xquery 轉(zhuǎn)換為 html?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!