问题
I am Using wso2esb4.8.0. I wish transform my messages into a different format using XSLT transformation.
My request messages are:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:open="http://www.openuri.org/" xmlns:env="http://eai.dd,kk/Envelope" xmlns:poin="http://eai.mng.par/hhh">
<soapenv:Header/>
<soapenv:Body>
<open:clientRequest>
<env:EaiEnvelope>
<env:Domain>1</env:Domain>
<env:Service>hhh</env:Service>
<env:ServiceId>1</env:ServiceId>
<env:Language>En</env:Language>
<env:UserId>hhh</env:UserId>
<env:Sender>hhh</env:Sender>
<env:MessageId>2210201395544</env:MessageId>
<env:CorrelationId>1</env:CorrelationId>
<env:GenTimeStamp>1</env:GenTimeStamp>
<env:SentTimeStamp>1</env:SentTimeStamp>
<env:Payload>
<poin:hhh>
<poin:Request>
<poin:Operation_Name>kk</poin:Operation_Name>
</poin:Request>
</poin:hhh>
</env:Payload>
</env:EaiEnvelope>
</open:clientRequest>
</soapenv:Body>
</soapenv:Envelope>
and
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:open="http://www.openuri.org/" xmlns:env="http://eai.dd,kk/Envelope" xmlns:acc="http://eai.mng.par/sd">
<soapenv:Header/>
<soapenv:Body>
<open:clientRequest>
<env:EaiEnvelope>
<env:Service>hhh</env:Service>
<env:Language>En</env:Language>
<env:UserId>hhh</env:UserId>
<env:Sender>hhh</env:Sender>
<env:MessageId>2210201395544</env:MessageId>
<env:CorrelationId>1</env:CorrelationId>
<env:GenTimeStamp>1</env:GenTimeStamp>
<env:SentTimeStamp>1</env:SentTimeStamp>
<env:Payload>
<acc:hhh>
<acc:Request>
<acc:CustDetails_InputData>
<acc:mno>989352105496</acc:mno>
</acc:CustDetails_InputData>
<acc:Operation_Name>getv</acc:Operation_Name>
</acc:Request>
</acc:hhh>
</env:Payload>
</env:EaiEnvelope>
</open:clientRequest>
</soapenv:Body>
</soapenv:Envelope>
Both are sample requests that I wish to transform into the formats below as per client request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:open="http://www.openuri.org/" xmlns:acc="http://eai.mng.kman/mng">
<soapenv:Header/>
<soapenv:Body>
<open:getv>
<acc:mng>
<!--You have a CHOICE of the next 3 items at this level-->
<acc:Request>
<acc:Operation_Name>getv</acc:Operation_Name>
<acc:BasicInfo>
<acc:Language>En</acc:Language>
<acc:UserId>hhh</acc:UserId>
<acc:Sender>hhh</acc:Sender>
<acc:MessageId>2210201395544</acc:MessageId>
<acc:Operation>getv</acc:Operation>
</acc:BasicInfo>
<acc:CustDetails_InputData>
<acc:mno>989352105496</acc:mno>
</acc:CustDetails_InputData>
</acc:Request>
</acc:mng>
</open:getv>
</soapenv:Body>
</soapenv:Envelope>
and
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:open="http://www.openuri.org/" xmlns:poin="http://eai.mng.kman/hhh">
<soapenv:Header/>
<soapenv:Body>
<open:kk>
<poin:hhh>
<poin:Request>
<poin:BasicInfo>
<poin:Language>En</poin:Language>
<poin:UserId>hhh</poin:UserId>
<poin:Sender>hhh</poin:Sender>
<poin:MessageId>2210201395544</poin:MessageId>
<poin:Operation>getv</poin:Operation>
</poin:BasicInfo>
<poin:Operation_Name>kk</poin:Operation_Name>
</poin:Request>
</poin:hhh>
</open:kk>
</soapenv:Body>
</soapenv:Envelope>
Like this various request will come. I need to transform the message in to that desired format. For this I have written a single XSLT which is working fine for this part:
<open:kk>
<poin:hhh>
<poin:Request>
<!-- problem here -->
<poin:Operation_Name>kk</poin:Operation_Name>
</poin:Request>
</poin:hhh>
</open:kk>
But I am unable to format this part (which should appear in the place indicated above). How do I get the namespace prefix?
<poin:BasicInfo>
<poin:Language>En</poin:Language>
<poin:UserId>hhh</poin:UserId>
<poin:Sender>hhh</poin:Sender>
<poin:MessageId>2210201395544</poin:MessageId>
<poin:Operation>getv</poin:Operation>
</poin:BasicInfo>
Which will take the message and format dynamically but bottom of message part. I am unable to do it.
My XSLT is:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:open="http://www.openuri.org/"
xmlns:env="http://eai.dd,kk/Envelope" version="1.0">
<xsl:param name="operation_name"></xsl:param>
<xsl:param name="UserId"></xsl:param>
<xsl:param name="Sender"></xsl:param>
<xsl:param name="MessageId"></xsl:param>
<xsl:param name="Language"></xsl:param>
<xsl:template match="/">
<xsl:element name="{concat('open:',$operation_name)}">
<xsl:element name="Basicinfo">
<xsl:element name="UserId">
<xsl:apply-templates select="UserId"/>
</xsl:element>
<xsl:element name="Sender">
<xsl:apply-templates select="Sender"/>
</xsl:element>
<xsl:element name="MessageId">
<xsl:apply-templates select="MessageId"/>
</xsl:element>
<xsl:element name="Language">
<xsl:apply-templates select="Language"/>
</xsl:element>
</xsl:element>
<xsl:copy-of select="//env:Payload/*"></xsl:copy-of>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Thanks in advance.
回答1:
I just did the implementation of your second output (with second input). I think this will be a good start to develop the other XSLT yourself:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:acc="http://eai.par.sd/gg" xmlns:open="http://www.openuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="http://eai.par.sd/sd" xmlns:env="http://eai.sd.sd/Envelope" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="soapenv:Body">
<xsl:copy>
<xsl:apply-templates select="open:clientRequest"/>
</xsl:copy>
</xsl:template>
<xsl:template match="open:clientRequest">
<open:ff>
<par:sd>
<par:Request>
<par:BasicInfo>
<par:Language>
<xsl:value-of select="//env:Language"/>
</par:Language>
<par:UserId><xsl:value-of select="//env:UserId"/></par:UserId>
<par:Sender><xsl:value-of select="//env:Sender"/></par:Sender>
<par:MessageId><xsl:value-of select="//env:MessageId"/></par:MessageId>
<par:Operation><xsl:value-of select="//acc:Operation_Name"/></par:Operation>
</par:BasicInfo>
<par:Operation_Name>ff</par:Operation_Name>
</par:Request>
</par:sd>
</open:ff>
</xsl:template>
<xsl:template match="*|text()|@*">
<xsl:copy>
<xsl:apply-templates select="*|text()|@*"/>
</xsl:copy>
</xsl:template>
This creates following output you requested:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:open="http://www.openuri.org/"
xmlns:env="http://eai.sd.sd/Envelope"
xmlns:acc="http://eai.par.sd/gg">
<soapenv:Header/>
<soapenv:Body>
<open:ff xmlns:par="http://eai.par.sd/sd">
<par:sd>
<par:Request>
<par:BasicInfo>
<par:Language>En</par:Language>
<par:UserId>par</par:UserId>
<par:Sender>par</par:Sender>
<par:MessageId>2210201395544</par:MessageId>
<par:Operation>dd</par:Operation>
</par:BasicInfo>
<par:Operation_Name>ff</par:Operation_Name>
</par:Request>
</par:sd>
</open:ff>
</soapenv:Body>
</soapenv:Envelope>
来源:https://stackoverflow.com/questions/23692702/how-to-get-the-dynamic-namespace-prefix-for-xslt-transformation-in-wso2wsb-4-8-0