Sunday, July 21, 2013
How to generate a random/unique number in XSLT ?
<xsl:variable name="RandomNum">
<xsl:value-of select="orcl:generate-guid()"/>
</xsl:variable>
Friday, June 28, 2013
XML - XSD Conversions
Below are useful sites to validate,
- To generate XML from given XSD
http://www.xsd2xml.com/
- Generate XSD from XML
http://www.freeformatter.com/xml-validator-xsd.html
- XML Validator
http://www.w3schools.com/xml/xml_validator.asp
Saturday, June 1, 2013
How to define a variable and assign a value using XSLT
How to define a variable and assign a value using XSLT
Define an element
Define an element
<xsl:variable name="sampleString">XML,XSLT,XPath,SVG,XPointer</xsl:variable>
<xsl:variable name="empName" select ="emp:EmployeeName"/>
Access the element
<name>
<xsl:value-of select="$empName"/>
</name>
How to use apply-template and call-template in XSLT
How to use <xsl:call-template> and <xsl:apply-template>
How to implement String tokenizer functionality using XSLT
I will demo an example how to use call-template recursively in XSLT, that is to tokenizea given string based on specified delimiter.
<xsl:call-template> - Using this, we can invoke a template by name of the template
This is how we can define a template with the name as 'tokenize' and which accepts two parameters
<xsl:template name="tokenize">
<xsl:param name="separator" select="';'"/>
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string,$separator)">
<ns0:Role>
<xsl:value-of select="substring-before($string,$separator)"/>
</ns0:Role>
<xsl:call-template name="tokenize">
<xsl:with-param name="string"
select="substring-after($string,$separator)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<ns0:Role>
<xsl:value-of select="$string"/>
</ns0:Role>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- This is how we invoke the template by passing the parameters
<xsl:call-template name="tokenize">
<xsl:with-param name="string"
select="oim:StringWithDelimiter"/>
</xsl:call-template>
<xsl:apply-template> - Using this we can invoke template by matching a specific element.
This is how we can define a template to invoke using <apply-template>
<xsl:template match="emp:Employee">
<emp:Name>
<xsl:value-of select="emp:FirstName"/>
</emp:Name>
</xsl:tempate>
How to invoke a template using <apply-template>
<xsl:apply-templates select="/emp:Employee"/>
How to implement String tokenizer functionality using XSLT
I will demo an example how to use call-template recursively in XSLT, that is to tokenizea given string based on specified delimiter.
<xsl:call-template> - Using this, we can invoke a template by name of the template
This is how we can define a template with the name as 'tokenize' and which accepts two parameters
<xsl:template name="tokenize">
<xsl:param name="separator" select="';'"/>
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string,$separator)">
<ns0:Role>
<xsl:value-of select="substring-before($string,$separator)"/>
</ns0:Role>
<xsl:call-template name="tokenize">
<xsl:with-param name="string"
select="substring-after($string,$separator)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<ns0:Role>
<xsl:value-of select="$string"/>
</ns0:Role>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- This is how we invoke the template by passing the parameters
<xsl:call-template name="tokenize">
<xsl:with-param name="string"
select="oim:StringWithDelimiter"/>
</xsl:call-template>
<xsl:apply-template> - Using this we can invoke template by matching a specific element.
This is how we can define a template to invoke using <apply-template>
<xsl:template match="emp:Employee">
<emp:Name>
<xsl:value-of select="emp:FirstName"/>
</emp:Name>
</xsl:tempate>
How to invoke a template using <apply-template>
<xsl:apply-templates select="/emp:Employee"/>
Saturday, April 13, 2013
How to invoke a web service from PL/SQL
Usecase: Invoke a webservice from PL/SQL Procedure,
Below is the sample code to invoke BPEL SOA process from PL/SQL stored procedure. Have this stored procedure defined in database.
Create or replace procedure TestBpelInvoke is
soap_request varchar2(3000);
soap_respond varchar2(3000);
http_req utl_http.req;
http_resp utl_http.resp;
resp xmltype;
l_xsl_nonamespace varchar2(1000) := null;
i number;
l_error_loc number;
call_error exception;
endpoint_url varchar2(1000);
response_value varchar2(100);
BEGIN
soap_request := '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:process xmlns:ns1="http://xmlns.oracle.com/BPELInvokeExample/BpelInvokeExample/BPELInvoke">
<ns1:input1>2</ns1:input1>
<ns1:input2>3</ns1:input2>
</ns1:process>
</soap:Body>
</soap:Envelope>';
endpoint_url := 'http://192.168.1.142:8001/soa-infra/services/default/BpelInvokeExample/bpelinvoke_client_ep';
http_req:= utl_http.begin_request(endpoint_url,'POST','HTTP/1.0');
utl_http.set_header(http_req, 'Content-Type', 'text/xml') ;
utl_http.set_header(http_req, 'Content-Length', length(soap_request)) ;
utl_http.set_header(http_req, 'SOAPAction', 'process');
utl_http.write_text(http_req, soap_request) ;
http_resp:= utl_http.get_response(http_req) ;
utl_http.read_text(http_resp, soap_respond) ;
utl_http.end_response(http_resp) ;
resp := XMLType.createXML(soap_respond);
l_xsl_nonamespace := '<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="comment()|processing-instruction()|/">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:choose>
<xsl:when test="name() != ''xmlns''">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>';
SELECT XMLTransform(resp, xmlType(l_xsl_nonamespace)) into resp from dual;
resp := resp.extract( '/'||'BPELInvoke'||'ProcessResponse/result/child::node()');
if (resp is null) then
response_value := '';
else
response_value := replace(replace(replace(resp.getStringVal(), '<', '<'), '>', '>'), '"', '"');
dbms_output.put_line('Response Value:'||response_value);
end if;
end;
Below is the sample code to invoke BPEL SOA process from PL/SQL stored procedure. Have this stored procedure defined in database.
Create or replace procedure TestBpelInvoke is
soap_request varchar2(3000);
soap_respond varchar2(3000);
http_req utl_http.req;
http_resp utl_http.resp;
resp xmltype;
l_xsl_nonamespace varchar2(1000) := null;
i number;
l_error_loc number;
call_error exception;
endpoint_url varchar2(1000);
response_value varchar2(100);
BEGIN
soap_request := '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:process xmlns:ns1="http://xmlns.oracle.com/BPELInvokeExample/BpelInvokeExample/BPELInvoke">
<ns1:input1>2</ns1:input1>
<ns1:input2>3</ns1:input2>
</ns1:process>
</soap:Body>
</soap:Envelope>';
endpoint_url := 'http://192.168.1.142:8001/soa-infra/services/default/BpelInvokeExample/bpelinvoke_client_ep';
http_req:= utl_http.begin_request(endpoint_url,'POST','HTTP/1.0');
utl_http.set_header(http_req, 'Content-Type', 'text/xml') ;
utl_http.set_header(http_req, 'Content-Length', length(soap_request)) ;
utl_http.set_header(http_req, 'SOAPAction', 'process');
utl_http.write_text(http_req, soap_request) ;
http_resp:= utl_http.get_response(http_req) ;
utl_http.read_text(http_resp, soap_respond) ;
utl_http.end_response(http_resp) ;
resp := XMLType.createXML(soap_respond);
l_xsl_nonamespace := '<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="comment()|processing-instruction()|/">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:choose>
<xsl:when test="name() != ''xmlns''">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>';
SELECT XMLTransform(resp, xmlType(l_xsl_nonamespace)) into resp from dual;
resp := resp.extract( '/'||'BPELInvoke'||'ProcessResponse/result/child::node()');
if (resp is null) then
response_value := '';
else
response_value := replace(replace(replace(resp.getStringVal(), '<', '<'), '>', '>'), '"', '"');
dbms_output.put_line('Response Value:'||response_value);
end if;
end;
Subscribe to:
Posts (Atom)