0

Replace span Element with its inner text whose class is "TAGGED_ITEM " in multiple rows with a column of type XML

    <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>

Once Element is updated it should looks as below.

<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>
Chat
  • 185
  • 1
  • 5
  • 15
  • 1
    You've [already asked (and gotten answers!)](http://stackoverflow.com/questions/35873792/replace-the-xml-element-with-new-element-in-sql-server) pretty much the same question before - how is this different? Please - **do not** ask the basically same question over and over and over again ! – marc_s Mar 08 '16 at 21:51
  • 1
    @marc_s this question is different from previous question. Here I am looking for replacing specific existing Span Elements which has class attribute value "TAGGED_ITEM " with its oven inner text. Completely different from previous question. – Chat Mar 09 '16 at 01:21

1 Answers1

1

This question had a particular namespace problem which, probably, had aroused the question. Eliminating namespaces on the match= does solve the problem. So an identity transform and a namespace-neutral matching gives the desired result:

<?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>

Result:

<?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>
zx485
  • 28,498
  • 28
  • 50
  • 59
  • Hi, Thank you for the answer ,but I am looking for Sql Query in solving it. – Chat Mar 09 '16 at 01:12
  • 1
    @Chatrapathi: Ok. Posted it, because you had the `XSLT` tag on it. I see you got it removed by now. No prob. – zx485 Mar 09 '16 at 12:58