【问题标题】:How to Add different name spaces to XML payload using XSLT如何使用 XSLT 向 XML 有效负载添加不同的名称空间
【发布时间】:2021-02-16 23:34:14
【问题描述】:

我有一个简单的 XML Payload 请求,我需要添加多个命名空间。我已经尝试了很多,但运气不错。你能帮助如何转换 XML 请求,

有效载荷

<insert>
    <u_email_domain>Test.eu</u_email_domain>
    <u_cost_center>costcenter123</u_cost_center>
    <u_department>ItDepartment</u_department>
    <u_family_name>Donald</u_family_name>
    <u_first_name>Trump</u_first_name>
    <u_foreseen_end_date/>
    <u_hris_id>1000091</u_hris_id>
    <u_job_title>Manager</u_job_title>
    <u_location>newyork</u_location>
    <u_manager_hris_id>10000421</u_manager_hris_id>
    <u_notification_recipients>dummy@email.com</u_notification_recipients>
    <u_vip>NO</u_vip>
</insert>

预期结果

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://www.service-now.com/u_hr_is">
    <soapenv:Body>
        <u:insert>
                <u:u_email_domain>Test.eu</u:u_email_domain>
                <u:u_cost_center>costcenter123</u:u_cost_center>
                <u:u_department>ItDepartment</u:u_department>
                <u:u_family_name>Donald</u:u_family_name>
                <u:u_first_name>Trump</u:u_first_name>
                <u:u_hris_id>1000091</u:u_hris_id>
                <u:u_job_title>Manager</u:u_job_title>
                <u:u_location>newyork</u:u_location>
                <u:u_manager_hris_id>10000421</u:u_manager_hris_id>
                <u:u_vip>NO</u:u_vip>
        </u:insert>
    </soapenv:Body>`enter code here`
</soapenv:Envelope>

【问题讨论】:

    标签: xslt namespaces


    【解决方案1】:

    Try this:
    
    <?xml version="1.0"?>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       >
      <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    
      <xsl:template match="/insert">
    
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://www.service-now.com/u_hr_is">
          <soapenv:Body>
            <u:insert>
              <u:u_email_domain>
                <xsl:value-of select="u_email_domain"/>
              </u:u_email_domain>
              <u:u_cost_center>
                <xsl:value-of select="u_cost_center"/>
              </u:u_cost_center>
              <u:u_department>
                <xsl:value-of select="u_department"/>
              </u:u_department>
              <u:u_family_name>
                <xsl:value-of select="u_family_name"/>
              </u:u_family_name>
              <u:u_first_name>
                <xsl:value-of select="u_first_name"/>
              </u:u_first_name>
              <u:u_hris_id>
                <xsl:value-of select="u_hris_id"/>
              </u:u_hris_id>
              <u:u_job_title>
                <xsl:value-of select="u_job_title"/>
              </u:u_job_title>
              <u:u_location>
                <xsl:value-of select="u_location"/>
              </u:u_location>
              <u:u_manager_hris_id>
                <xsl:value-of select="u_manager_hris_id"/>
              </u:u_manager_hris_id>
              <u:u_vip>
                <xsl:value-of select="u_vip"/>
              </u:u_vip>
            </u:insert>
          </soapenv:Body>
        </soapenv:Envelope>
      </xsl:template>
    </xsl:stylesheet>

    【讨论】:

      猜你喜欢
      • 2018-06-25
      • 1970-01-01
      • 2010-12-22
      • 2013-04-05
      • 1970-01-01
      • 2019-01-02
      • 2017-06-13
      • 1970-01-01
      • 2011-07-13
      相关资源
      最近更新 更多