0

我需要使用 XSLT fron 字段在另一个中提取一个 xml。

<?xml version="1.0" encoding="UTF-8" ?> 
<ns:JDBC_SELECT xmlns:ns="namepace/nt">
<row>
<KEY>19</KEY> 
<QUEUE_TYPE>2</QUEUE_TYPE> 
<EVENT_STATUS>0</EVENT_STATUS> 
<EVENT_TYPE>New Work Package Request</EVENT_TYPE> 
<CONTENT><?xml version="1.0" encoding="utf-8" standalone="yes"?><event xmlns:ns="namespace/nt" reference="0000000000" source="NBA" target="SAP" timestamp="2013-02-04T14:32:01.836+00:00" type="New Work Package Request" version="1.0" id="19"><new-work-package-request-event><work-order-id>11</work-order-id><personnel-id>ra_a</personnel-id><request-timestamp>2013-02-04T14:32:01.836+00:00</request-timestamp><new-notification-request><type>Z2</type><requirement-code>RI0D</requirement-code><main-work-centre>0102</main-work-centre><planner-group>L00</planner-group><functional-location-id>1024</functional-location-id><short-text>SET UP/REMOVE ISOLATION RUN</short-text><long-text>SET UP/REMOVE ISOLATION RUN, 1024, NORTON FOXLEY (PRV) NORTON FOXLEY Nightline Increase: (l/h)</long-text><personnel-resp-id>12157</personnel-resp-id><cost-centre>3600</cost-centre></new-notification-request><new-work-order-request><type>ZPM2</type></new-work-order-request></new-work-package-request-event></event></CONTENT> 
</row>
</ns:JDBC_SELECT>

<xsl:transform xmlns:xsl="namespace/nt" version="1.0">
  <xslutput method="xml"/>
  <xsl:template match="/">
    <xsl:copy-of select="//CONTENT"/>
  </xsl:template>
</xsl:transform>

但不是运气。任何想法?

4

1 回答 1

0

XML 无效 - 它不能包含第二个

<?xml version="1.0" encoding="utf-8"?>

元素内的声明。因为它不会加载。

XSLT 中也存在问题 - 名称空间必须是http://www.w3.org/1999/XSL/Transform

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
      <xsl:copy-of select="//CONTENT"/>
    </xsl:template>

</xsl:stylesheet>

去掉<?xml....>XML 中的第二个声明后,上面的 XSLT 就可以工作了,产生以下输出:

<?xml version="1.0" encoding="utf-8"?>
<CONTENT xmlns:ns="namepace/nt">
  <event reference="0000000000" source="NBA" target="SAP" timestamp="2013-02-04T14:32:01.836+00:00" type="New Work Package Request" version="1.0" id="19" xmlns:ns="namespace/nt">
    <new-work-package-request-event>
      <work-order-id>11</work-order-id>
      <personnel-id>ra_a</personnel-id>
      <request-timestamp>2013-02-04T14:32:01.836+00:00</request-timestamp>
      <new-notification-request>
        <type>Z2</type>
        <requirement-code>RI0D</requirement-code>
        <main-work-centre>0102</main-work-centre>
        <planner-group>L00</planner-group>
        <functional-location-id>1024</functional-location-id>
        <short-text>SET UP/REMOVE ISOLATION RUN</short-text>
        <long-text>SET UP/REMOVE ISOLATION RUN, 1024, NORTON FOXLEY (PRV) NORTON FOXLEY Nightline Increase: (l/h)</long-text>
        <personnel-resp-id>12157</personnel-resp-id>
        <cost-centre>3600</cost-centre>
      </new-notification-request>
      <new-work-order-request>
        <type>ZPM2</type>
      </new-work-order-request>
    </new-work-package-request-event>
  </event>
</CONTENT>
于 2013-02-05T14:57:51.177 回答