0

我正在尝试将预定义变量的值添加到我的 XML 的每个单独的子节点。我发现了这个问题SO Question及其答案,这对我来说看起来很整洁。

但是,我不能将变量@modification_time用作属性的输入。

DECLARE @xml XML=
N'<ContentTemplate>
  <Tab Title="Lesson">
    <Section Title="Lesson Opening" />
    <Section Title="Lesson/Activity" />
  </Tab>
  <Tab Title="Wrap Up and Assessment">
    <Section Title="Lesson Closing" />
    <Section Title="Tracking Progress/Daily Assessment" />
  </Tab>
  <Tab Title="Differentiated Instruction">
    <Section Title="Strategies - Keyword" />
    <Section Title="Strategies – Text" />
    <Section Title="Resources" />
    <Section Title="Acceleration/Enrichment" />
  </Tab>
  <Tab Title="District Resources">
    <Section Title="Related Content Items" />
    <Section Title="Other" />
  </Tab>
</ContentTemplate>';

我不知道它是否可能以及如何将变量值添加到子节点。

DECLARE @modification_time nvarchar(30); 
SET @modification_time = FORMAT(CURRENT_TIMESTAMP,'yyyy-MM-ddTHH:mm:ss' ) ;  

SET @xml=@xml.query(
'<ContentTemplate>
{
for $t in /ContentTemplate/Tab
   return 
   <Tab Title="{$t/@Title}" PortletName="CommunitiesViewer" ModificationTime="VariableValuehere" >
   {$t/*}
   </Tab>
}
</ContentTemplate>');

SELECT @xml
4

0 回答 0