0

I need your help to modify an xml by deleting elements and attributes the modification I'm making can't reach the elements here my base xml

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="https://urldebas.com">
    <id>https://urldebas.com</id>
    <title type="text">value</title>
    <updated>2022-10-12T17:11:09Z</updated>
    <author>
        <name/>
    </author>
    <link href="EQUIPMENTSet" rel="self" title="EQUIPMENTSet"/>
    <entry>
        <id>https://urldebas.com</id>
        <title type="text">EQUIPMENTSet(Plant='1268',EquipmentID='10042621')</title>
        <updated>2022-10-12T17:11:09Z</updated>
        <category term="ZPM_MASTER_DATA_SRV.EQUIPMENT" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
        <link href="EQUIPMENTSet(Plant='1268',EquipmentID='10042621')" rel="self" title="EQUIPMENT"/>
        <content type="application/xml">
            <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
                <d:Plant>1268</d:Plant>
                <d:EquipmentID>10042621</d:EquipmentID>
                <d:DateOfLastChange>2021-05-03T00:00:00</d:DateOfLastChange>
                <d:Description>AEROTHERME No1</d:Description>
                <d:FunctionalLocation>FR29-1268-BA70-AERG</d:FunctionalLocation>
                <d:MainWorkCenter>PM1268SG</d:MainWorkCenter>
                <d:CostCenter>BE01G001</d:CostCenter>
                <d:SortField>AEROTHERME 1</d:SortField>
                <d:ObjectType></d:ObjectType>
                <d:WorkCenter></d:WorkCenter>
            </m:properties>
        </content>
    </entry>
</feed>

I want to delete the xml:base attribute in feed the id element in feed and in entry to get this xml

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<title type="text">value</title>
<updated>2022-10-12T17:11:09Z</updated>
<author>
    <name />
</author>
<link href="EQUIPMENTSet" rel="self" title="EQUIPMENTSet" />
<entry>
    <title type="text">EQUIPMENTSet(Plant='1268',EquipmentID='10042621')</title>
    <updated>2022-10-12T17:11:09Z</updated>
    <category term="ZPM_MASTER_DATA_SRV.EQUIPMENT" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <link href="EQUIPMENTSet(Plant='1268',EquipmentID='10042621')" rel="self" title="EQUIPMENT" />
    <content type="application/xml">
        <m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
            <d:Plant>1268</d:Plant>
            <d:EquipmentID>10042621</d:EquipmentID>
            <d:DateOfLastChange>2021-05-03T00:00:00</d:DateOfLastChange>
            <d:Description>AEROTHERME No1</d:Description>
            <d:FunctionalLocation>FR29-1268-BA70-AERG</d:FunctionalLocation>
            <d:MainWorkCenter>PM1268SG</d:MainWorkCenter>
            <d:CostCenter>BE01G001</d:CostCenter>
            <d:SortField>AEROTHERME 1</d:SortField>
            <d:ObjectType></d:ObjectType>
            <d:WorkCenter></d:WorkCenter>
        </m:properties>
    </content>
</entry>

My Xslt file

    <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="@xml:base"/>
<xsl:template match="feed/id"/>
<xsl:template match="feed/entry/id"/>
</xsl:stylesheet>
Sidiki
  • 1
  • 1

1 Answers1

0

Note that your source document contains a default namespace declaration xmlns="http://www.w3.org/2005/Atom" which means that unprefixed element names in the document (including the feed, entry, and id elements) are in the namespace whose identifier is http://www.w3.org/2005/Atom (Note also that the default namespace applies to elements but does not apply to attributes; an unprefixed attribute name is always in the empty namespace).

So to refer to the Atom elements in your XSLT you will need to declare the Atom namespace in your stylesheet, and associate it with a prefix, and then use that prefix in your XPath expressions:

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:atom="http://www.w3.org/2005/Atom">
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/> 
        </xsl:copy>
    </xsl:template>
    <xsl:template match="@xml:base"/>
    <xsl:template match="atom:feed/atom:id"/>
    <xsl:template match="atom:feed/atom:entry/atom:id"/>
</xsl:stylesheet>
Conal Tuohy
  • 2,561
  • 1
  • 8
  • 15