开发者

XSLT NOT WORKING... for Attribute

i have this XSLT and XML payload that i am wanting to transform. but the output xml does not contain the attribute for element engine.

any help would be appreciated?

this is my xslt

    <?xml version="1.0" encoding="UTF-8" ?>
    <?oracle-xsl-mapper
    <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
    <mapSources>
    <source type="WSDL">
    <schema location="../HTTPBinding.wsdl"/>
    <rootElement name="Envelope" namespace="http://HPES.org/"/>
    </source>
    </mapSources>
    <mapTargets>
    <target type="WSDL">
    <schema location="../Service1.wsdl"/>
    <rootElement name="Envelope" namespace="http://HPES.org/"/>
    </target>
    </mapTargets>
    <!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.4.0(build 110106.1932.5682) AT [TUE JUN 07 11:17:07 CDT 2011]. -->
    ?>
    <xsl:stylesheet version="1.0"
    xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
    xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
    xmlns:inp2="http://HPES.org/"
    xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
    xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
    xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
    xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:med="http://schemas.oracle.com/mediator/xpath"
    xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
    xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
    xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
    xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:inp1="http://tempuri.org/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:ora="http://schemas.oracle.com/xpath/extension"
    xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
    xmlns:tns="http://oracle.com/sca/soapservice/Application1/Project1/Service1"
    xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
    exclude-result-prefixes="xsi xsl inp2 xsd inp1 wsdl tns bpws xp20 mhdr bpel oraex开发者_开发问答t dvm hwf med ids bpm xdk xref ora socket ldap">
    <xsl:template match="/">
    <inp2:Envelope>
    <Body>
    <soapP1>
    <soapP2>
    <engine>
    <xsl:attribute name="value">
    <xsl:value-of select="/inp2:Envelope/Body/soapP1/soapP2/engine/@value"/>
    </xsl:attribute>
    <xsl:attribute name="txnElapsedTime">
    <xsl:value-of select="/inp2:Envelope/Body/soapP1/soapP2/engine/@txnElapsedTime"/>
    </xsl:attribute>
    <xsl:value-of select="/inp2:Envelope/Body/soapP1/soapP2/engine"/>
    </engine>
    </soapP2>
    </soapP1>
    </Body>
    </inp2:Envelope>
    </xsl:template>
    </xsl:stylesheet>

this is my input xml

    <soap:Envelope xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <soapP1>
    <soapP2>
    <engine value="1" txnElapsedTime="0.05"/>
    </soapP2>
    </soapP1>
    </soap:Body>
    </soap:Envelope>

this is my output where the attribute are lost.....

    <?xml version="1.0" encoding="utf-8"?>
    <inp2:Envelope xmlns:inp2="http://HPES.org/">
    <Body>
    <soapP1>
    <soapP2>
    <engine value="" txnElapsedTime="">
    </engine>
    </soapP2>
    </soapP1>
    </Body>
    </inp2:Envelope>         


Seems that what you need is this simple and short transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:inp2="http://HPES.org/"
 exclude-result-prefixes="inp2">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="engine">
  <inp2:Envelope>
    <Body>
        <soapP1>
            <soapP2>
             <engine>
              <xsl:copy-of select="@*|node()"/>
             </engine>  
            </soapP2>
        </soapP1>
    </Body>
  </inp2:Envelope>
 </xsl:template>
</xsl:stylesheet>

when applied to the provided XML document:

<soap:Envelope
 xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <soapP1>
            <soapP2>
                <engine value="1" txnElapsedTime="0.05"/>
            </soapP2>
        </soapP1>
    </soap:Body>
</soap:Envelope>

the wanted result is produced:

<inp2:Envelope xmlns:inp2="http://HPES.org/">
   <Body>
      <soapP1>
         <soapP2>
            <engine value="1" txnElapsedTime="0.05"/>
         </soapP2>
      </soapP1>
   </Body>
</inp2:Envelope>

Explanation: Just one template, matching engine -- with all necessary literal-result-elements as the simplest way to have them in the desired new namespaces and to get rid of the other namespace nodes that the original elements own.


Your XSLT is using the wrong XPATH to reference the attributes. If I enter the following XSLT (using the namespace soap instead of inp2) into this online XSLT test tool, I get the result I think you're looking for:

XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper
<!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
<mapSources>
<source type="WSDL">
<schema location="../HTTPBinding.wsdl"/>
<rootElement name="Envelope" namespace="http://HPES.org/"/>
</source>
</mapSources>
<mapTargets>
<target type="WSDL">
<schema location="../Service1.wsdl"/>
<rootElement name="Envelope" namespace="http://HPES.org/"/>
</target>
</mapTargets>
<!-- GENERATED BY ORACLE XSL MAPPER 11.1.1.4.0(build 110106.1932.5682) AT [TUE JUN 07 11:17:07 CDT 2011]. -->
?>
<xsl:stylesheet version="1.0"
xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
xmlns:inp2="http://HPES.org/"
xmlns:mhdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.mediator.service.common.functions.MediatorExtnFunction"
xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable"
xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dvm="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue"
xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:med="http://schemas.oracle.com/mediator/xpath"
xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
xmlns:bpm="http://xmlns.oracle.com/bpmn20/extensions"
xmlns:xdk="http://schemas.oracle.com/bpel/extension/xpath/function/xdk"
xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:inp1="http://tempuri.org/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ora="http://schemas.oracle.com/xpath/extension"
xmlns:socket="http://www.oracle.com/XSL/Transform/java/oracle.tip.adapter.socket.ProtocolTranslator"
xmlns:tns="http://oracle.com/sca/soapservice/Application1/Project1/Service1"
xmlns:ldap="http://schemas.oracle.com/xpath/extension/ldap"
exclude-result-prefixes="xsi xsl inp2 xsd inp1 wsdl tns bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref ora socket ldap">
<xsl:template match="/">
<inp2:Envelope>
<Body>
<soapP1>
<soapP2>
<engine>
<xsl:attribute name="value">
<xsl:value-of select="/soap:Envelope/Body/soapP1/soapP2/engine/@value"/>
</xsl:attribute>
<xsl:attribute name="txnElapsedTime">
<xsl:value-of select="/soap:Envelope/Body/soapP1/soapP2/engine/@txnElapsedTime"/>
</xsl:attribute>
<xsl:value-of select="/soap:Envelope/Body/soapP1/soapP2/engine"/>
</engine>
</soapP2>
</soapP1>
</Body>
</inp2:Envelope>
</xsl:template>
</xsl:stylesheet>

RESULT:

<?xml version="1.0" encoding="UTF-8"?>
<inp2:Envelope xmlns:inp2="http://HPES.org/">
<Body>
<soapP1>
<soapP2>
<engine value="1" txnElapsedTime="0.05"/>
</soapP2>
</soapP1>
</Body>
</inp2:Envelope>


In fidelity with your transform (and with XSLT specs), to make things work you need to:

  • Declare the namespace prefix for the uri http://schemas.xmlsoap.org/soap/envelope/
  • add the new prefix to the exclude list
  • select the elements according to the declared prefix

So, you have to add the following line to your (huge) list:

xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"

and change the exclude-result-prefixes to:

exclude-result-prefixes="soap xsi xsl inp2 xsd inp1 wsdl tns bpws xp20 mhdr bpel oraext dvm hwf med ids bpm xdk xref ora socket">

And then change your XPath to select elements accordingly. For example:

<xsl:value-of select="/soap:Envelope/soap:Body/soapP1/soapP2/engine/@value"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜