本文介紹了使用 xquery 轉換為 html?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有以下數據庫電子郵件的 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>
推薦答案
我想出了一個更少黑客攻擊的方案.唯一的問題是如果值為空,它將創建
而不是
.將電子郵件發送到某些舊 Outlook 客戶端時會導致一些布局問題.
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>')
這篇關于使用 xquery 轉換為 html?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!