提取XML片段以用作前缀mod作为输出



我试图提出一个描述性标题...大声笑...

无论如何;这可能很简单,但我在这里挣扎着。我有一个需要处理的输入。我需要这样做:

  1. 提取"过程"及其所有子女。
  2. 将所有"客户端" NS前缀更改为" FHA"
  3. 在"过程"标签中添加基本名称空间(是的,我知道这很时髦,但这是我想要的资源。)

输入文件

<TOTALRequest-Response-Keys xmlns="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
  <fha_case_number>2812883060</fha_case_number>
  <loan_number>1000006611</loan_number>
  <score_dt>2019/01/31 16:23:55</score_dt>
  <aus>ZFWF</aus>
  <times_enqueued>1</times_enqueued>
  <TOTALRequest-Response xmlns:client="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
    <client:process>
      <client:monthly_income/>
      <!-- many elements -->
      <client:loanapp>
        <client:loanapptype>MISMOAUS2.4</client:loanapptype>
        <ns1:loanappdata xmlns="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard" xmlns:ns2="http://mismo.org/aus/" xmlns:ns1="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
          <ns2:LOAN_APPLICATION MISMOVersionID="2.4"/>
          <!-- many elements ns1:whatever -->
          </ns1:loanappdata>
          </client:loanapp>
     </client:process>
     <client:processResponse/>
  </TOTALRequest-Response>
</TOTALRequest-Response-Keys>

所需的输出

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:f17="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
<soapenv:Body>
<fha:process xmlns:fha="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
      <fha:monthly_income>
            <fha:loanapp>
        <fha:loanapptype>MISMOAUS2.4</fha:loanapptype>
        <ns1:loanappdata xmlns="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard" xmlns:ns2="http://mismo.org/aus/" xmlns:ns1="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
          <ns2:LOAN_APPLICATION MISMOVersionID="2.4">
        </ns1:loanappdata>
      </fha:loanapp>
    </fha:process>
 </soapenv:Body>
</soapenv:Envelope>

我当前; y有

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fha="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard"
xmlns:client="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard"
xmlns:ns1="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
xmlns:ns2="http://mismo.org/aus/">
<xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
	<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:f17="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
	<soapenv:Body>
	<fha:process xmlns:fha="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
	<xsl:copy>
		<xsl:copy-of select="/*/*/*:process/child::*"/>
	</xsl:copy>
	</fha:process>
	</soapenv:Body>
	</soapenv:Envelope>
</xsl:template>
<!--
<xsl:template match="client:*" name="change_prefix">
	<xsl:element name="fha:{local-name()}">
		<xsl:apply-templates select="."/>
	</xsl:element>
</xsl:template>
<xsl:template match="/">
	<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:f17="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
	<soapenv:Body>
	<xsl:copy>
		<xsl:copy-of select="/*/*/child::*"/>
	</xsl:copy>
	<xsl:apply-templates select="change_prefix" />
	</soapenv:Body>
	</soapenv:Envelope>
</xsl:template>
-->
 
</xsl:stylesheet>

我尝试了很多事情,但是我觉得我只是在墙上扔面条。:(

这个可以适合您吗?

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fha="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard"
xmlns:client="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
<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="/fha:TOTALRequest-Response-Keys">
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:f17="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
        <soapenv:Body>
            <xsl:apply-templates select="fha:TOTALRequest-Response/client:process"/>
        </soapenv:Body>
    </soapenv:Envelope>
</xsl:template>
<xsl:template match="client:*">
    <xsl:element name="fha:{local-name()}">
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
</xsl:stylesheet>

事实证明,我不需要使用嵌入式片段做任何事情。端点能够掌握嵌入式文档的默认命名空间(但是如果有人想回应我不会反对。)

我需要对迈克尔的回答进行的唯一更改是在"信封"标签中添加命名空间声明。(米歇尔(Micheal)绝不知道结束过程需要另一个命名空间。)

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fha="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard"
xmlns:client="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard"
xmlns:ns2="http://mismo.org/aus/" 
xmlns:ns1="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
<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="/fha:TOTALRequest-Response-Keys">
    <soapenv:Envelope 
    	xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    	xmlns:f17="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard"
	xmlns:fha="http://xmlns.oracle.com/F17CTOTALScorecard/F17CTOTALScorecard/F17CTOTALScorecard">
        <soapenv:Body>
            <xsl:apply-templates select="fha:TOTALRequest-Response/client:process"/>
        </soapenv:Body>
    </soapenv:Envelope>
</xsl:template>
<xsl:template match="client:*">
    <xsl:element name="fha:{local-name()}">
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>
</xsl:stylesheet>

最新更新