홈>
발송인이 임의로 사용할 네임 스페이스 접두사를 미리 모르고 XML 메시지의 하나 이상의 요소에 대한 네임 스페이스 URI를 바꾸려면 어떻게해야합니까?
이 질문의 형식은 여러 번 요청되었지만, 내가 찾은 모든 답변 (여기 및 다른 사이트에서)은 접두사에 대한 정확한 지식을 전제로합니다. 접두사는 정의에 따라 임의적이며 이에 대한 해결책은 사용 된 접두사에 대한 지식이 필요하지 않습니다.
해결책이 있지만 출력에 필요없는 정크가 생깁니다. 간단한 입력 :
<?xml version="1.0" encoding="UTF-8"?>
<myThing xmlns:s="http://tempuri3.org/">
<s:thisThing>
<thatThing xmlns="http://cheapCookies.org/"/>
<anotherThing xmlns="http://kingkong.org">
<thisThing/>
</anotherThing>
</s:thisThing>
</myThing>
이것은 XSLT입니다 :
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="sourceNamespace" select="'http://tempuri3.org/'" />
<xsl:param name="targetNamespace" select="'http://tempuri.org'"/>
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="node() | @*" name="identity">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="namespace-uri() = $sourceNamespace">
<xsl:element name="{name()}" namespace="{$targetNamespace}">
<xsl:apply-templates select="node() | @*"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="identity"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
이것은 위 XSLT의 출력입니다 :
<?xml version="1.0" encoding="utf-8"?>
<myThing xmlns:s="http://tempuri3.org/">
<s:thisThing xmlns:s="http://tempuri.org">
<thatThing xmlns="http://cheapCookies.org/" xmlns:s="http://tempuri3.org/"/>
<anotherThing xmlns="http://kingkong.org" xmlns:s="http://tempuri3.org/">
<thisThing/>
</anotherThing>
</s:thisThing>
</myThing>
이것은 원하는 결과입니다 :
<?xml version="1.0" encoding="utf-8"?>
<myThing xmlns:s="http://tempuri.org/">
<s:thisThing>
<thatThing xmlns="http://cheapCookies.org/"/>
<anotherThing xmlns="http://kingkong.org">
<thisThing/>
</anotherThing>
</s:thisThing>
</myThing>
- 답변 # 1
관련 자료
- javascript - jsp 태그를 HTMLRewriter로 바꾸는 방법
- 정수 키로 TIMEDICT를 만드는 방법은 무엇입니까?
- python - 스택/언 스테 킹 할 때 NaN으로 행을 풀지 않는 방법은 무엇입니까?
- javascript - for 루프를 Array map ()으로 대체
- node.js - FFMPEG 및 노드에서 스트림을 사용하는 방법
- javascript - 삼항 연산자로 IF를 수행하는 방법
- swift - xmlcoder로 xml을 디코딩하는 방법은 무엇입니까?
- r - 최대 이상 치가있는 날을 찾는 방법
- c++ - std - : initializer_list 로 생성자를 만드는 방법
- javascript - localstorage의 데이터로 저장소를 초기화하는 방법은 무엇입니까?
- python - Discordpy로 메시지를 보내는 방법
- python - n 개의 마지막 행을 NaN으로 바꾸기
- php - href로 2 개의 값을 보내는 방법은 무엇입니까?
- reactjs - react-places-autocomplete로 우편 번호를 얻는 방법
- mongodb - 토큰으로 사용자를 식별하는 방법은 무엇입니까?
- unicode - Inno Setup으로 BOM 파일로 UTF-16을 저장하는 방법
- How to make foreach work with this PHP script - 이 php 스크립트로 foreach를 작동시키는 방법 - get api
- javascript - 약속과 함께 withLatestFrom을 사용하는 방법?
- vue.js - 모델을 함수로 바인딩하는 방법
- sql server - 유형 객체로 SQL 프로 시저를 테스트하는 방법
관련 질문
- java xslt를 사용하여 하나의 xml 파일에서 다른 파일로 데이터를 복사하는 방법
- xml : 텍스트가 무언가 xslt와 같을 때 일치합니다
- xml : XSLT 2.0 : 각 -Group의 현재 색인에 따라 요소 값 평가 및 수정
- html : 로컬 XSL 참조 XML 파일
- XSLT는 중첩 된 XML 요소를 쉼표로 구분 된 값 문자열이있는 하나의 요소로 작성합니다.
- c# : XSLT XPath 요청은 HTML로 변환에서 작동하지 않습니다.
- java : XSLT 3.0 -XSLT 3.0 XML-to-JSON ()에서 개체 배열을 가져올 수 없음
- xml : XSLT 1.0을 사용하여 항목을 그룹화 할 수 있습니까?
- xml : XSLT의 특정 노드 값에 따라 노드를 가져 오는 것
- xml : XSLT에서 특정 속성 값을 사용하여 요소의 각 발생을 계산합니까?
와이즈 비즈
그러면 아마해야 할 일 :
사용 된 정확한 프로세서에 따라 결과가 약간 다를 수 있습니다. 예를 들어 Saxon 6.5는 다음을 반환합니다.
<?xml version="1.0" encoding="UTF-8"?> <myThing xmlns:s="http://tempuri3.org/"> <thisThing xmlns="http://tempuri.org"> <thatThing xmlns="http://cheapCookies.org/"/> <anotherThing xmlns="http://kingkong.org"> <thisThing/> </anotherThing> </thisThing> </myThing>