remove attribute on document node

user4207598

I have to remove the xsi:schemaLocation but I don't get it to work, I think I do something wrong in wt:Envelope/wt:Body/wt:MessageParts/*[not(name() ='xsi:schemaLocation')] definition, but don't know how to solve this

xml source:

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
  <Header>
    <MessageId>{AAE4C191-6D18-4823-A29D-9C6CA68113C2}</MessageId>
    <Action>http://tempuri.org/VendPaymentsService/find</Action>
  </Header>
  <Body>
   <MessageParts xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
     <Document xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03 pain.001.001.03.xsd" 
          xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <CstmrCdtTrfInitn>
          ....
        </CstmrCdtTrfInitn>
      </Document>
    </MessageParts>
  </Body>
</Envelope>

My xslt

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:wt="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" 
                xmlns:s1="http://schemas.microsoft.com/dynamics/2008/01/documents/VendPayments" 
                version="1.0">
  <xsl:output method="xml" encoding="iso-8859-1" />
  <xsl:template match="/">
    <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="utf-8"?&gt;</xsl:text>
    <xsl:copy-of select="wt:Envelope/wt:Body/wt:MessageParts/*[not(name() ='xsi:schemaLocation')]" />
  </xsl:template>
</xsl:stylesheet>

result

<?xml version="1.0" encoding="utf-8"?>
<Document 
 xsi:schemaLocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03 pain.001.001.03.xsd" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CstmrCdtTrfInitn>
..
</CstmrCdtTrfInitn>
</Document>

what am I doing wrong?

michael.hor257k

<xsl:copy-of> performs a deep copy; you cannot exclude individual nodes. Note also that xsi:schemaLocation is an attribute, not an element.

Try it this way, perhaps?

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wt="http://schemas.microsoft.com/dynamics/2011/01/documents/Message" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="/">
    <xsl:apply-templates select="wt:Envelope/wt:Body/wt:MessageParts/*" />
</xsl:template>

<xsl:template match="@xsi:schemaLocation"/>

</xsl:stylesheet>

Note:
You should never be required to use a hack like this:

<xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="utf-8"?&gt;</xsl:text>

If you want your output to have utf-8 encoding, say so in the <output> element.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Freemarker: Remove particular attribute from node

분류에서Dev

How do you get a node that contains a child node with a given attribute value in an XML document using sql server?

분류에서Dev

How to remove or recover password from a LibreOffice document

분류에서Dev

Jquery Remove Clear Top CSS attribute

분류에서Dev

Javascript Remove specific attribute from style

분류에서Dev

How to Add and remove attribute if found specific class

분류에서Dev

How to unescape an element and remove the namespace attribute

분류에서Dev

XML grab attribute from specific element node

분류에서Dev

XPath - how to select node with multiple attribute values?

분류에서Dev

php - change value to src attribute if 'cid:' are found in html document

분류에서Dev

Echo XML child node value based on node attribute value

분류에서Dev

partially update fields in a document - findAndModify remove all other fields?

분류에서Dev

How to remove unique constraint for a model attribute of an abstract model after inheritance?

분류에서Dev

XSLT remove data if attribute value is higher than threshold

분류에서Dev

jQuery on remove not working parent node fire empty ()

분류에서Dev

xslt remove duplicate in child and parent node

분류에서Dev

Trouble combining element in 'each' do block with node attribute

분류에서Dev

XSL transform grandchild node values to element attribute value

분류에서Dev

How do you query a MongoDB document where an array attribute is null or of zero length?

분류에서Dev

Kinetic.Node 삭제 : remove () 또는 destroy ()?

분류에서Dev

PowerShell: Remove an xml node if its childnodes matches specific criteria

분류에서Dev

How to remove duplicate fonts in a PDF document with 150,000 embedded fonts?

분류에서Dev

Remove all comments and comments block in a Word-Document (.docx) using PowerShell

분류에서Dev

Node.JS에서 생성 된 Document Restful API

분류에서Dev

xslt node-set use in key function - find children by parent attribute

분류에서Dev

How to remove last node from linked list without using double pointer

분류에서Dev

document.querySelector ()는 Node의 인스턴스가 아닌 요소를 반환합니다.

분류에서Dev

node.js에서 악몽 API로 document.querySelector를 반환 할 수 없습니다.

분류에서Dev

Node.js TreeWalker 및 / 또는 document.createRange ()가 단일 요소를 선택하지 않습니다.

Related 관련 기사

  1. 1

    Freemarker: Remove particular attribute from node

  2. 2

    How do you get a node that contains a child node with a given attribute value in an XML document using sql server?

  3. 3

    How to remove or recover password from a LibreOffice document

  4. 4

    Jquery Remove Clear Top CSS attribute

  5. 5

    Javascript Remove specific attribute from style

  6. 6

    How to Add and remove attribute if found specific class

  7. 7

    How to unescape an element and remove the namespace attribute

  8. 8

    XML grab attribute from specific element node

  9. 9

    XPath - how to select node with multiple attribute values?

  10. 10

    php - change value to src attribute if 'cid:' are found in html document

  11. 11

    Echo XML child node value based on node attribute value

  12. 12

    partially update fields in a document - findAndModify remove all other fields?

  13. 13

    How to remove unique constraint for a model attribute of an abstract model after inheritance?

  14. 14

    XSLT remove data if attribute value is higher than threshold

  15. 15

    jQuery on remove not working parent node fire empty ()

  16. 16

    xslt remove duplicate in child and parent node

  17. 17

    Trouble combining element in 'each' do block with node attribute

  18. 18

    XSL transform grandchild node values to element attribute value

  19. 19

    How do you query a MongoDB document where an array attribute is null or of zero length?

  20. 20

    Kinetic.Node 삭제 : remove () 또는 destroy ()?

  21. 21

    PowerShell: Remove an xml node if its childnodes matches specific criteria

  22. 22

    How to remove duplicate fonts in a PDF document with 150,000 embedded fonts?

  23. 23

    Remove all comments and comments block in a Word-Document (.docx) using PowerShell

  24. 24

    Node.JS에서 생성 된 Document Restful API

  25. 25

    xslt node-set use in key function - find children by parent attribute

  26. 26

    How to remove last node from linked list without using double pointer

  27. 27

    document.querySelector ()는 Node의 인스턴스가 아닌 요소를 반환합니다.

  28. 28

    node.js에서 악몽 API로 document.querySelector를 반환 할 수 없습니다.

  29. 29

    Node.js TreeWalker 및 / 또는 document.createRange ()가 단일 요소를 선택하지 않습니다.

뜨겁다태그

보관