2013-02-05 141 views
0

我需要使用XSLT fron字段在另一个XML文件中提取xml。XSLT - 从另一个XML中获取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> 

但不是运气。 有什么想法?

+0

如何生成此XML文件? –

回答

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> 
+0

嗨,是的,我知道,但他们发给我一个XML内的另一个,然后,我必须提取它。 它必须是一种方法,但我不知道。 – Cerbero22

+0

我不认为你可以使用XSLT - 你必须编写一个处理XML文本的程序,或者至少可以删除额外的声明,然后你可以在生成的'clean XML'上使用XSLT, – MiMo