veer xslt requirement : replace namespace prefix

 <?xml version="1.0" encoding="UTF-8"?>

<root xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"

      xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

    <m:properties xmlns="http://www.w3.org/2005/Atom"

                 xmlns:georss="http://www.georss.org/georss"

                 xmlns:gml="http://www.opengis.net/gml">

        <d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>

        <d:Id m:type="Edm.Int32">1</d:Id>

    </m:properties>

</root>


<?xml version="1.0" encoding="UTF-8"?><root xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

    <m:properties xmlns="http://www.w3.org/2005/Atom" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">

        <FileSystemObjectType xmlns="" m:type="Edm.Int32">0</FileSystemObjectType>

        <Id xmlns="" m:type="Edm.Int32">1</Id>

    </m:properties>

</root>

----------------------


xslt code

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


  <!-- Identity template copies all nodes and attributes unchanged -->

  <xsl:template match="@*|node()">

    <xsl:copy>

      <xsl:apply-templates select="@*|node()"/>

    </xsl:copy>

  </xsl:template>


  <!-- Template to match elements with "d:" namespace prefix and remove the prefix -->

  <xsl:template match="*[starts-with(name(), 'd:')]">

    <xsl:element name="{substring-after(name(), 'd:')}">

      <xsl:apply-templates select="@*|node()"/>

    </xsl:element>

  </xsl:template>


</xsl:stylesheet>

---------------------------------

testing

https://xsltfiddle-beta.liberty-development.net/

got solution from chatgpt. 
1) saved as xml
2) fold all
3) took min xml file
4) validate xml file in chatgpt
5) after corrected. asked again, to remove namespace prefix d:
6) tested solution online tool.

Popular posts from this blog

pss book : శ్రీకృష్ణుడు దేవుడా, భగవంతుడా completed , second review needed. 26th April 2024

pss book: గురు ప్రార్థనామంజరి . completed 21st july 2024

pss book: కధల జ్ఞానము read review pending. 25th june 2024