2017-02-22 71 views
0

Моего ввода XML является, как показано ниже:Перемещение узла с пространствами имен внутри другого узла с помощью XSLT

<?xml version="1.0" encoding="UTF-8"?> 
<response> 
    <response> 
     <case> 
     <CRDATTIM>2017-02-13-07.04.12.346420</CRDATTIM> 
     <issues> 
      <row> 
       <IKEY>2017-02-13-07.04.10.293420T01</IKEY> 
      </row> 
     </issues> 
     </case> 
     <results> 
     <row> 
      <IKEY>2017-02-13-07.04.10.293420T01</IKEY> 
     </row> 
     </results> 
    </response> 
    <results> 
     <children xmlns="http://www.dsttechnologies.com/awd/rest/v1" xmlns:xs="http://www.w3.org/2001/XMLSchema" total="1"> 
     <sourceInstance recordType="source" id="2017-02-22-01.02.41.198440O01"> 
      <link rel="attachments" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/attachments" /> 
      <link rel="fieldvalues" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/fieldvalues" /> 
      <link rel="form" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/form" /> 
      <link rel="history" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/history" /> 
      <link rel="parents" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/parents" /> 
      <link rel="presentation summary" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/presentationsummary" /> 
      <link rel="self" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01" /> 
      <link rel="archive" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/archive" /> 
      <permission>Update</permission> 
      <secondaryTagline /> 
      <businessAreaName href="awdServer/awd/services/v1/businessareas/CS2XAA">CS2XAA</businessAreaName> 
      <date>2017-02-22</date> 
      <summary>CS2XAA - 2XSRCTYP - 044000000049 - Updateable - Create Date:2017-02-22 - Create Time:01:02:41-06:00</summary> 
      <time>01:02:41-06:00</time> 
      <typeName href="awdServer/awd/services/v1/businessareas/CS2XAA/types/2XSRCTYP">2XSRCTYP</typeName> 
      <createStation>DT77214</createStation> 
      <createUser href="awdServer/awd/services/v1/users/DT77214">Reddy, BATCH (DT77214)</createUser> 
      <objectFormat format="I">IOCA</objectFormat> 
      <objectId>044000000049</objectId> 
      <opticalStatus status="2">Original state</opticalStatus> 
      <receiveDate>2017-02-22</receiveDate> 
      <receiveTime>01:02:41-06:00</receiveTime> 
      <securityLevel>0</securityLevel> 
     </sourceInstance> 
     </children> 
    </results> 
</response> 

Теперь я хочу, чтобы переместить /response/results/children внутри /response/response/case/issues/row.

Мой выходной файл XML должен быть, как показано ниже:

<?xml version="1.0" encoding="UTF-8"?> 
<response> 
    <response> 
     <case> 
     <CRDATTIM>2017-02-13-07.04.12.346420</CRDATTIM> 
     <issues> 
      <row> 
       <IKEY>2017-02-13-07.04.10.293420T01</IKEY> 
       <children xmlns="http://www.dsttechnologies.com/awd/rest/v1" xmlns:xs="http://www.w3.org/2001/XMLSchema" total="1"> 
        <sourceInstance recordType="source" id="2017-02-22-01.02.41.198440O01"> 
        <link rel="attachments" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/attachments" /> 
        <link rel="fieldvalues" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/fieldvalues" /> 
        <link rel="form" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/form" /> 
        <link rel="history" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/history" /> 
        <link rel="parents" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/parents" /> 
        <link rel="presentation summary" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/presentationsummary" /> 
        <link rel="self" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01" /> 
        <link rel="archive" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/archive" /> 
        <permission>Update</permission> 
        <secondaryTagline /> 
        <businessAreaName href="awdServer/awd/services/v1/businessareas/CS2XAA">CS2XAA</businessAreaName> 
        <date>2017-02-22</date> 
        <summary>CS2XAA - 2XSRCTYP - 044000000049 - Updateable - Create Date:2017-02-22 - Create Time:01:02:41-06:00</summary> 
        <time>01:02:41-06:00</time> 
        <typeName href="awdServer/awd/services/v1/businessareas/CS2XAA/types/2XSRCTYP">2XSRCTYP</typeName> 
        <createStation>DT77214</createStation> 
        <createUser href="awdServer/awd/services/v1/users/DT77214">Reddy, BATCH (DT77214)</createUser> 
        <objectFormat format="I">IOCA</objectFormat> 
        <objectId>044000000049</objectId> 
        <opticalStatus status="2">Original state</opticalStatus> 
        <receiveDate>2017-02-22</receiveDate> 
        <receiveTime>01:02:41-06:00</receiveTime> 
        <securityLevel>0</securityLevel> 
        </sourceInstance> 
       </children> 
      </row> 
     </issues> 
     </case> 
     <results> 
     <row> 
      <IKEY>2017-02-13-07.04.10.293420T01</IKEY> 
     </row> 
     </results> 
    </response> 
    <results> 
     <children xmlns="http://www.dsttechnologies.com/awd/rest/v1" xmlns:xs="http://www.w3.org/2001/XMLSchema" total="1"> 
     <sourceInstance recordType="source" id="2017-02-22-01.02.41.198440O01"> 
      <link rel="attachments" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/attachments" /> 
      <link rel="fieldvalues" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/fieldvalues" /> 
      <link rel="form" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/form" /> 
      <link rel="history" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/history" /> 
      <link rel="parents" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/parents" /> 
      <link rel="presentation summary" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/presentationsummary" /> 
      <link rel="self" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01" /> 
      <link rel="archive" type="application/vnd.dsttechnologies.awd+xml" href="awdServer/awd/services/v1/instances/2017-02-22-01.02.41.198440O01/archive" /> 
      <permission>Update</permission> 
      <secondaryTagline /> 
      <businessAreaName href="awdServer/awd/services/v1/businessareas/CS2XAA">CS2XAA</businessAreaName> 
      <date>2017-02-22</date> 
      <summary>CS2XAA - 2XSRCTYP - 044000000049 - Updateable - Create Date:2017-02-22 - Create Time:01:02:41-06:00</summary> 
      <time>01:02:41-06:00</time> 
      <typeName href="awdServer/awd/services/v1/businessareas/CS2XAA/types/2XSRCTYP">2XSRCTYP</typeName> 
      <createStation>DT77214</createStation> 
      <createUser href="awdServer/awd/services/v1/users/DT77214">Reddy, BATCH (DT77214)</createUser> 
      <objectFormat format="I">IOCA</objectFormat> 
      <objectId>044000000049</objectId> 
      <opticalStatus status="2">Original state</opticalStatus> 
      <receiveDate>2017-02-22</receiveDate> 
      <receiveTime>01:02:41-06:00</receiveTime> 
      <securityLevel>0</securityLevel> 
     </sourceInstance> 
     </children> 
    </results> 
</response> 

Я попытался с помощью следующего XSL, но не может получить желаемый результат

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v="http://www.dsttechnologies.com/awd/rest/v1" version="2.0" exclude-result-prefixes="v"> 
    <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 
    <xsl:strip-space elements="*" /> 
    <xsl:template match="@* | node()"> 
     <xsl:copy> 
     <xsl:apply-templates select="@* | node()" /> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="//response/response/case/issues/row"> 
     <xsl:copy> 
     <xsl:apply-templates select="node()|@*" /> 

      <xsl:apply-templates select="v:response/results/children" /> 

     </xsl:copy> 
    </xsl:template> 
</xsl:stylesheet> 

Любые мысли о том, где я делаю ошибку ?

ответ

1

Вы не за горами, но у вас есть префикс пространства имен в неправильном месте. children - единственный элемент в пространстве имен вашего пути. response не находится в пространстве имен. Кроме того, вам нужно изменить выбор для поиска из узла документа, а не текущего совпадающего узла.

Таким образом, вместо этого ..

<xsl:apply-templates select="v:response/results/children" /> 

ли это ...

<xsl:apply-templates select="/response/results/v:children" /> 
+0

Это идеальный .. !! +1 для объяснения. –

 Смежные вопросы

  • Нет связанных вопросов^_^