Xsl stylesheet empty result Datapower - web-services

Good Morning.
I need some help with that:
I have a XML firewall with loopback backend. Either I have a web services that can login in my local machine with a code, and the response show my in the same lable: "code", a new code.
The problem is, when i build the XML firewall, in the policy rules, I use the tranform with XSL, but the response service is empty.
The code of my xsl is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dpconfig="http://www.datapower.com/param/config" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" xmlns:regexp="http://exslt.org/regular-expressions">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:variable name="call_IdentToken">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.ws.identify.com" xmlns:code="http://code.ws.identify.com">
<soapenv:Header/>
<soapenv:Body>
<ser:validaCode>
<ser:obj>
<code:code>2016</code:code>
</ser:obj>
</ser:validaCode>
</soapenv:Body>
</soapenv:Envelope>
</xsl:variable>
<xsl:variable name="result_IdentToken" select="dp:soap-call('http://localhost:8080/ValidaCodigo/services/ImplCode', $call_IdentToken)"/>
</xsl:template>
</xsl:stylesheet>

Your stylesheet does not output anything. If you want it to return the contents of the result_IdentToken variable, you should copy it to the output context after you set it.
<xsl:copy-of select="$result_IdentToken"/>

Related

Values are not present in transformed xml in xslt transformation

I am trying to transform one xml using xslt but I am getting empty xml nodes. Please let me know what I am missing.
My source xml is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:ProcessPartsOrder xmlns="http://www.host.com/ERP/Sales/Entities" xmlns:ns2="http://www.host.com/ERP/Sales/ProcessPartsOrder" xmlns:ns4="http://www.host.com/ERP/Sales/ValueObjects" xmlns:ns3="http://www.host.com/ERP/Sales/Aggregates/PartsOrder">
<ns2:MessageHeader>
<CultureCode>en-US</CultureCode>
<SenderNameCode>S3</SenderNameCode>
<CreationDateTime>2019-03-19T22:48:16</CreationDateTime>
<BODID>e27c5244-4f18-4343-a15f-e509b8a75802</BODID>
</ns2:MessageHeader>
</ns2:ProcessPartsOrder>
I want to transform into below format:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:proc="http://www.host.com/ERP/Sales/ProcessPartsOrder" xmlns:ent="http://www.host.com/ERP/Sales/Entities" xmlns:par="http://www.host.com/ERP/Sales/Aggregates/PartsOrder" xmlns:val="http://www.host.com/ERP/Sales/ValueObjects">
<soapenv:Header/>
<soapenv:Body>
<proc:ProcessPartsOrder>
<proc:MessageHeader>
<ent:CultureCode>en-US</ent:CultureCode>
<ent:SenderNameCode>S3</ent:SenderNameCode>
<ent:CreationDateTime>2013-01-23T12:41:36-05:00</ent:CreationDateTime>
<ent:BODID>e27c5244-4f18-4343-a15f-e509b8a75802</ent:BODID>
</proc:MessageHeader>
</proc:ProcessPartsOrder>
</soapenv:Body>
</soapenv:Envelope>
My xslt looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns2="http://www.host.com/ERP/Sales/CustomerOrderManagement"
xmlns:ns3="http://www.host.com/ERP/Sales/Aggregates/PartsOrder"
xmlns:ns4="http://www.host.com/ERP/Sales/ValueObjects"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="ns2 ns3 ns4 xs">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/*">
<soapenv:Envelope xmlns="http://www.host.com/ERP/Sales/CustomerOrderManagement"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:proc="http://www.host.com/ERP/Sales/ProcessPartsOrder"
xmlns:ent="http://www.host.com/ERP/Sales/Entities"
xmlns:par="http://www.host.com/ERP/Sales/Aggregates/PartsOrder"
xmlns:val="http://www.host.com/ERP/Sales/ValueObjects">
<soapenv:Header/>
<soapenv:Body>
<proc:ProcessPartsOrder>
<proc:MessageHeader>
<ent:CultureCode>
<xsl:value-of select="/ns2:ProcessPartsOrder/ns2:MessageHeader/CultureCode"/>
</ent:CultureCode>
<ent:SenderNameCode>
<xsl:value-of select="ns2:ProcessPartsOrder/ns2:MessageHeader/SenderNameCode"/>
</ent:SenderNameCode>
<ent:CreationDateTime>
<xsl:value-of select="ns2:ProcessPartsOrder/ns2:MessageHeader/CreationDateTime"/>
</ent:CreationDateTime>
<ent:BODID>
<xsl:value-of select="ns2:ProcessPartsOrder/ns2:MessageHeader/BODID"/>
</ent:BODID>
</proc:MessageHeader>
</proc:ProcessPartsOrder>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
All I am getting an expected xml with empty values.
I believe I am missing something for which I need help.
Thanks.
You were giving the XPaths to the values a different namespace than in the source. Hence they return empty. The namespace itself differs.
In your source you define the default namespace as
xmlns="http://www.host.com/ERP/Sales/Entities"
But the ns2 namespace in the XSLT is defined as
xmlns:ns2="http://www.host.com/ERP/Sales/CustomerOrderManagement"
Or course you have to use the same namespace in the XPath expression of the XSLT. There you defined the first namespace as proc. So change your template to the following
<xsl:template match="/">
<soapenv:Envelope xmlns="http://www.host.com/ERP/Sales/CustomerOrderManagement"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:proc="http://www.host.com/ERP/Sales/ProcessPartsOrder"
xmlns:ent="http://www.host.com/ERP/Sales/Entities"
xmlns:par="http://www.host.com/ERP/Sales/Aggregates/PartsOrder"
xmlns:val="http://www.host.com/ERP/Sales/ValueObjects">
<soapenv:Header/>
<soapenv:Body>
<proc:ProcessPartsOrder>
<proc:MessageHeader>
<ent:CultureCode>
<xsl:value-of select="/proc:ProcessPartsOrder/proc:MessageHeader/ent:CultureCode"/>
</ent:CultureCode>
<ent:SenderNameCode>
<xsl:value-of select="/proc:ProcessPartsOrder/proc:MessageHeader/ent:SenderNameCode"/>
</ent:SenderNameCode>
<ent:CreationDateTime>
<xsl:value-of select="/proc:ProcessPartsOrder/proc:MessageHeader/ent:CreationDateTime"/>
</ent:CreationDateTime>
<ent:BODID>
<xsl:value-of select="/proc:ProcessPartsOrder/proc:MessageHeader/ent:BODID"/>
</ent:BODID>
</proc:MessageHeader>
</proc:ProcessPartsOrder>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
Or, another approach, you can add the namespace
xmlns:ent="http://www.host.com/ERP/Sales/Entities"
to the stylesheet element and add a modified identity template for the ent: elements which changes the namespace of each copied element:
<xsl:template match="ent:*">
<xsl:element name="ent:{local-name()}" namespace="http://www.host.com/ERP/Sales/Entities">
<xsl:apply-templates select="#*|node()"/>
</xsl:element>
</xsl:template>
Then your main template could be simplified to
<xsl:template match="/">
<soapenv:Envelope xmlns="http://www.host.com/ERP/Sales/CustomerOrderManagement"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:proc="http://www.host.com/ERP/Sales/ProcessPartsOrder"
xmlns:ent="http://www.host.com/ERP/Sales/Entities"
xmlns:par="http://www.host.com/ERP/Sales/Aggregates/PartsOrder"
xmlns:val="http://www.host.com/ERP/Sales/ValueObjects">
<soapenv:Header/>
<soapenv:Body>
<proc:ProcessPartsOrder>
<proc:MessageHeader>
<xsl:apply-templates select="/proc:ProcessPartsOrder/proc:MessageHeader/ent:*"/>
</proc:MessageHeader>
</proc:ProcessPartsOrder>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
To also copy attributes, add an unmodifed identity template.

dynamic XSLT Transformation

I have an incoming simple xml request below and need to transform to below SOAP message with correct name space.and in the incoming XML request the name space are not coming so while forming the SOAP message we need to take care of the name space also. Is there any XSLT code snippet which will help me to achieve that.
Note - We need to do this XSLT transformation dynamically like the incoming request can be any element like "GetImageRequest" so based on this element need to construct the name space. (probably we can keep all the name space in one xml file and need to construct the SOAP message)
Incoming XML request:
<request>
<payload>
<GetImageRequest>
<participantId>1191152220010</participantId>
<participantCode>131029</participantCode>
<groupCode>027198</groupCode>
<userType>EE</userType>
<clientName>Test</clientName>
<shoeboxID>123444</shoeboxID>
<imageID>45235</imageID>
</GetImageRequest>
</payload>
</request>
==================
Need to Construct below SOAP message with proper namespace.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<get:GetShoeboxItemRequest xmlns:get="urn:webservice/server/mobile/shoebox/types/v1/GetShoeboxItem">
<get:participantId>1060687620010</get:participantId>
<get:participantCode>1060687620010</get:participantCode>
<get:groupCode>027198</get:groupCode>
<get:userType>EE</get:userType>
<get:clientName>Test</get:clientName>
<get:shoeboxID>123444</get:shoeboxID>
</get:GetShoeboxItemRequest>
</soapenv:Body>
</soapenv:Envelope>
Need a quick help on this . XSLT code snippet would be helpful.
This transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pRequestedItemName" select="'Shoebox'"/>
<xsl:variable name="vUpper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="vLower" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="vLcItemName" select=
"translate($pRequestedItemName, $vUpper, $vLower)"/>
<xsl:variable name="vDynNamespace" select=
"concat('urn:webservice/server/mobile/', $vLcItemName, '/types/v1/Get', 'Item')"/>
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<xsl:element name="get:Get{$pRequestedItemName}ItemRequest"
namespace="{$vDynNamespace}">
<xsl:apply-templates select="/*/*/GetImageRequest/node()"/>
</xsl:element>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
<xsl:template match="*">
<xsl:element name="get:{name()}" namespace="{$vDynNamespace}">
<xsl:copy-of select="namespace::*|#*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
When applied on the provided source XML document:
<request>
<payload>
<GetImageRequest>
<participantId>1191152220010</participantId>
<participantCode>131029</participantCode>
<groupCode>027198</groupCode>
<userType>EE</userType>
<clientName>Test</clientName>
<shoeboxID>123444</shoeboxID>
<imageID>45235</imageID>
</GetImageRequest>
</payload>
</request>
produces the wanted, correct result:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<get:GetShoeboxItemRequest
xmlns:get="urn:webservice/server/mobile/shoebox/types/v1/GetItem">
<get:participantId>1191152220010</get:participantId>
<get:participantCode>131029</get:participantCode>
<get:groupCode>027198</get:groupCode>
<get:userType>EE</get:userType>
<get:clientName>Test</get:clientName>
<get:shoeboxID>123444</get:shoeboxID>
<get:imageID>45235</get:imageID>
</get:GetShoeboxItemRequest>
</soapenv:Body>
</soapenv:Envelope>
Explanation:
The full power of the <xsl:element> instruction is used.
Use of AVT (Attribute Value Templates)
The only variable part of the dynamic namespace should be provided as a global parameter by the invoker of the transformation.
If you need to construct a completely dynamic namespace (such as passed in a global parameter by the invoker of the transformation), see this answer.
UPDATE:
The OP clarified in a comment that he can have all request-specific namespaces collected in a separate XML document or in a global parameter.
Here is the solution to this clarified problem:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pRequestData">
<r name="GetImageRequest"
ns="urn:webservice/server/mobile/shoebox/types/v1/GetShoeboxItem"/>
<r name="SaveShoeBoxitemRequest"
ns="urn:webservice/server/mobile/shoebox/types/v1/SaveShoeboxItem"/>
<r name="SaveClaimWithReceiptRequest"
ns="urn:webservice/server/mobile/shoebox/types/v1/SaveClaimAndReceipt"/>
<r name="GetThumbNailImageRequest"
ns="urn:webservice/server/mobile/shoebox/types/v1/GetThumbnail"/>
<r name="AttachReceiptwithExistingClaimRequest"
ns="urn:webservice/server/mobile/shoebox/types/v1/AttachClaimAndReceipt"/>
</xsl:param>
<xsl:variable name="vParams" select="document('')/*/xsl:param[#name='pRequestData']"/>
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<xsl:apply-templates select="/*/*/*"/>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
<xsl:template match="*">
<xsl:param name="pKey" select="local-name()"/>
<xsl:element name="get:{local-name()}" namespace="{$vParams/*[#name = $pKey]/#ns}">
<xsl:copy-of select="namespace::*|#*"/>
<xsl:apply-templates>
<xsl:with-param name="pKey" select="$pKey"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the following XML document (the provided one with a second, differently named child of payload):
<request>
<payload>
<GetImageRequest>
<participantId>1191152220010</participantId>
<participantCode>131029</participantCode>
<groupCode>027198</groupCode>
<userType>EE</userType>
<clientName>Test</clientName>
<shoeboxID>123444</shoeboxID>
<imageID>45235</imageID>
</GetImageRequest>
<SaveShoeBoxitemRequest>
<participantId>1191152220010</participantId>
<participantCode>131029</participantCode>
<groupCode>027198</groupCode>
<userType>EE</userType>
<clientName>Test</clientName>
<shoeboxID>123444</shoeboxID>
<imageID>45235</imageID>
</SaveShoeBoxitemRequest>
</payload>
</request>
The wanted, correct (unlike "solutions" in other answers) result is produced:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<get:GetImageRequest
xmlns:get="urn:webservice/server/mobile/shoebox/types/v1/GetShoeboxItem">
<get:participantId>1191152220010</get:participantId>
<get:participantCode>131029</get:participantCode>
<get:groupCode>027198</get:groupCode>
<get:userType>EE</get:userType>
<get:clientName>Test</get:clientName>
<get:shoeboxID>123444</get:shoeboxID>
<get:imageID>45235</get:imageID>
</get:GetImageRequest>
<get:SaveShoeBoxitemRequest
xmlns:get="urn:webservice/server/mobile/shoebox/types/v1/SaveShoeboxItem">
<get:participantId>1191152220010</get:participantId>
<get:participantCode>131029</get:participantCode>
<get:groupCode>027198</get:groupCode>
<get:userType>EE</get:userType>
<get:clientName>Test</get:clientName>
<get:shoeboxID>123444</get:shoeboxID>
<get:imageID>45235</get:imageID>
</get:SaveShoeBoxitemRequest>
</soapenv:Body>
</soapenv:Envelope>
So if i know what all namespace for those 5 elements i can put in one
xml file and can retrieve from that XML file. or as you mentioned can
define those name space in global document.
If you have a map of which namespace to use with which "root" element name, you could just as well keep it in the stylesheet itself.
Here's an example (using made-up namespaces, since you did not specify your own):
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="http://www.example.com/my"
exclude-result-prefixes="my">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<my:ns-map>
<ns root="GetImageRequest">urn:webservice/a/b/GetShoeboxItem</ns>
<ns root="SaveShoeBoxitemRequest">urn:webservice/c/d/SaveShoeBoxitemRequest</ns>
<ns root="SaveClaimWithReceiptRequest">urn:webservice/e/f/SaveClaimWithReceiptRequest</ns>
<ns root="GetThumbNailImageRequest">urn:webservice/g/h/GetThumbNailImageRequest</ns>
<ns root="AttachReceiptwithExistingClaimRequest">urn:webservice/i/k/AttachReceiptwithExistingClaimRequest</ns>
</my:ns-map>
<xsl:variable name="root" select="name(/request/payload/*)"/>
<xsl:variable name="ns" select="document('')/xsl:stylesheet/my:ns-map/ns[#root=$root]"/>
<xsl:template match="/">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<xsl:apply-templates select="request/payload/*" />
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
<xsl:template match="*" >
<xsl:element name="get:{local-name()}" namespace="{$ns}">
<xsl:copy-of select="#*"/>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
</xsl:stylesheet>

get node name from namespace

this is my xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:end="http://endpoint.ggg.com/">
<soapenv:Header/>
<soapenv:Body>
<end:onlineExpressRemit>
<channelCode>NBPS</channelCode>
</end:onlineExpressRemit>
</soapenv:Body>
</soapenv:Envelope>
and this is my xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:end="http://endpoint.ggg.com/" >
<xsl:template match="/">
<xsl:value-of name="ggg2" select="/soapenv:Envelope/soapenv:Body/*[namespace-uri()]"/>
</xsl:template>
</xsl:stylesheet>
my expected output is display only
onlineExpressRemit
i am very new for xslt, i try name(), local-name() alot others method, however no luck, i cant retrieve only node-name, any help will do, thank you!
You can try using local-name(soapenv:Envelope/soapenv:Body/*), for example, the following XSL transformation :
<xsl:stylesheet version="1.0" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:end="http://endpoint.ggg.com/" >
<xsl:output method="text" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:element name="root">
<xsl:value-of select="local-name(soapenv:Envelope/soapenv:Body/*)"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
when applied to your XML sample, yield the following output :
<root>onlineExpressRemit</root>
Note: I added <root> element just because in online XSLT processor I used for testing, there was error when root element is absent. Usually, setting <xsl:output> is enough to be able to output a non-XML result : XSLT: Transforming into non-xml content?

How to select the value from an attribute that has a colon in xslt?

I am working with xslt to handle the results that are returned from a web service. I first need to determine which web service the results are for. I know that the tag platformCore:record has the attribute "xsi:type="listRel:Contact or "xsi:type="listEmp:Employee". I am trying to select the value that the attribute is storing, but the colon seems to be causing some issues when I attempt to select the value.
Here is what I tried, but fails to work.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:variable name="Type"><xsl:value-of select="//*[local-name()='searchResponse']//*[local-name()='searchResult']//*[local-name()='recordList']//*[local-name()='record']#xsi:type"/></xsl:variable>
<root>
<test><xsl:value-of select="$Type"/></test>
</root>
</xsl:template>
</xsl:stylesheet>
Here is a simple sample
<?xml version="1.0" encoding="UTF-8"?>
<searchResponse:searchResponse xmlns="urn:messages_2012_2.platform.webservices.itsthesuite.com"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:searchResponse="urn:messages_2012_2.platform.webservices.itsthesuite.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<platformCore:searchResult xmlns:platformCore="urn:core_2012_2.platform.webservices.itsthesuite.com">
<platformCore:status isSuccess="true"/>
<platformCore:totalRecords>1</platformCore:totalRecords>
<platformCore:recordList>
<platformCore:record internalId="154098" xsi:type="listRel:Contact" xmlns:listRel="urn:relationships_2012_2.lists.webservices.itsthesuite.com">
<listRel:entityId>John Smith</listRel:entityId>
<listRel:firstName>John</listRel:firstName>
<listRel:lastName>Smith</listRel:lastName>
<listRel:phone>(777) 777-7777</listRel:phone>
<listRel:email>john.smith#yormoms.com</listRel:email>
</platformCore:record>
</platformCore:recordList>
</platformCore:searchResult>
</searchResponse:searchResponse>
I need the solution to work for this sample as well.
Employee Sample
<?xml version="1.0" encoding="UTF-8"?>
<searchResponse xmlns="urn:messages_2012_2.platform.webservices.netsuite.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:searchResponse="urn:messages_2012_2.platform.webservices.netsuite.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<platformCore:searchResult xmlns:platformCore="urn:core_2012_2.platform.webservices.netsuite.com" >
<platformCore:status isSuccess="true"/>
<platformCore:totalRecords>1</platformCore:totalRecords>
<platformCore:recordList>
<platformCore:record internalId="158778" xsi:type="listEmp:Employee" xmlns:listEmp="urn:employees_2012_2.lists.webservices.netsuite.com">
<listEmp:entityId>331sfds Dipo Chaponda</listEmp:entityId>
<listEmp:salutation>Mr.</listEmp:salutation>
<listEmp:firstName>Dipo</listEmp:firstName>
<listEmp:lastName>Chaponda</listEmp:lastName>
<listEmp:email>dchapond#youmm.com</listEmp:email>
</platformCore:record>
</platformCore:recordList>
</platformCore:searchResult>
</searchResponse>
You can select an attribute using local name similarly to what you are already doing, but by prefacing the * with an #:
#*[local-name() = 'type']
However, littering your XPaths with local-name() = and double slashes is not a good practice. You should use namespaces properly, and use precise paths when they are known, although it seems that is not an option for the elements in your case because they are using different namespaces in the two examples. This should work:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
exclude-result-prefixes="sr pc xsi"
>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:variable name="Type">
<xsl:value-of select="*[local-name() = 'searchResponse']/
*[local-name() = 'searchResult']/
*[local-name() = 'recordList']/
*[local-name() = 'record']/
#xsi:type"/>
</xsl:variable>
<root>
<test>
<xsl:value-of select="$Type"/>
</test>
</root>
</xsl:template>
</xsl:stylesheet>
When run on your sample input, this produces the expected result:
<root>
<test>listRel:Contact</test>
</root>

XPATH Challenge - Want to Copy an Inner Element

I am struggling with what should be a simple XSL: Copy the updateResponse from the message below (note: I need XPATH 1.0 syntax for my integration system compatibility):
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:n="urn:enterprise.soap.sforce.com">
<soapenv:Body>
<updateResponse>
<result>
<id>001S000000J1Bu0IAF</id>
<success>true</success>
</result>
</updateResponse>
</soapenv:Body>
</soapenv:Envelope>
I simply want the result structure to be:
<updateResponse xmlns="urn:enterprise.soap.sforce.com">
<result>
<id>001S000000J1Bu0IAF</id>
<success>true</success>
</result>
</updateResponse>
I am able to copy the soap objects, but am unsuccessful in copying the children of the soapenv:Body element. The first copy-of works for Body, but the second does not resolve the XPATH. My XMLSPY tool xpath query editor says the xpath is valid, but the XSL does not resolve.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:urn="enterprise.soap.sforce.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:namespace-alias stylesheet-prefix="soapenv" result-prefix="foo"/>
<xsl:template match="/">
<xsl:apply-templates select="/soapenv:Envelope/soapenv:Body/urn:updateResponse"/>
</xsl:template>
<xsl:template match="/soapenv:Envelope/soapenv:Body/urn:updateResponse">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
Your namespaces are mismatched between your data and your stylesheet, that seems to be the only problem.
In your stylesheet document, change this:
xmlns:urn="enterprise.soap.sforce.com"
to this:
xmlns:urn="urn:enterprise.soap.sforce.com"
Then it will match the declared namespaces in your original input file.
This stylesheet:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<xsl:template match="/soapenv:Envelope/soapenv:Body//*">
<xsl:element name="{local-name()}"
namespace="urn:enterprise.soap.sforce.com">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Output:
<updateResponse xmlns="urn:enterprise.soap.sforce.com">
<result>
<id>001S000000J1Bu0IAF</id>
<success>true</success>
</result>
</updateResponse>
Note: First, the namespace declaration in your stylesheet is wrong. It should be xmlns:urn="urn:enterprise.soap.sforce.com". Second, for an exact result you need to strip in scope namespaces (there are three: xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/", xmlns="urn:enterprise.soap.sforce.com" (default), and xmlns:n="urn:enterprise.soap.sforce.com)
The namespaces in this document are weird; you have xmlns and xmlns:n both assigned to the same namespace. It looks like //soapenv:updateResponse should work. Have you tried that?