2016-03-08 71 views
-1

更換SPAN元素,其內部的文本,它的類「TAGGED_ITEM」多行與替換XML span元素在SQL Server中span標籤的內部文本

<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2"> 
     <ItemBody> 
     <div class="item_text"> 
         <div> 
          <span class="TAGGED_ITEM " id="c1_ae1">This is a map on a grid.</span> 
          <span class="TAGGED_ITEM " id="c1_ae2"> It shows a car.</span> 
         </div> 
<span class="TAGGED_ITEM " id="c1_ae3"> It shows a car on Road.</span> 
        </div> 
     </ItemBody> 
    </Item> 

一旦元素被更新其XML類型的列應該看起來如下。

<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2"> 
     <ItemBody> 
     <div class="item_text"> 
         <div> 
          This is a map on a grid. 
          It shows a car. 
         </div> 
          It shows a car on Road. 
        </div> 
     </ItemBody> 
    </Item> 
+1

你[已經要求(並得到答案!)](HTTP:// stackoverflow.com/questions/35873792/replace-the-xml-element-with-new-element-in-sql-server)幾乎相同的問題之前 - 這是如何不同?請 - **不要**一遍又一遍地提出基本相同的問題! –

+0

@marc_s這個問題與以前的問題不同。在這裏,我正在尋找用烤箱內部文本替換具有類屬性值「TAGGED_ITEM」的特定現有Span元素。與以前的問題完全不同。 – Chat

回答

1

這個問題有一個特殊的命名空間問題,可能引起了這個問題。消除match=上的命名空間確實可以解決問題。因此,一個身份變換和命名空間中立匹配給出了期望的結果:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  
    <xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="*[local-name() = 'span']"> 
    <xsl:value-of select="text()" /> 
    </xsl:template> 
</xsl:stylesheet> 

結果:

<?xml version="1.0"?> 
<Item xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2" title="1234"> 
    <ItemBody> 
    <div class="item_text"> 
        <div> 
         This is a map on a grid. 
         It shows a car. 
        </div> 
       </div> 
    </ItemBody> 
</Item> 
+0

嗨,謝謝你的答案,但我正在尋找解決它的Sql查詢。 – Chat

+1

@Chatrapathi:好的。張貼它,因爲你有'XSLT'標籤。我看到你現在已經把它移走了。沒問題。 – zx485