tags:

views:

28

answers:

2

Below is the example file

<?xml version='1.0' encoding='UTF-8'?>
<Document xmlns='urn:iso:std:iso:20022:tech:xsd:pain.002.001.02' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'&gt;  
<pain.002.001.02>
------------
-------------
-------------

</pain.002.001.02>
</Document> 

Below is the XSLT Transformation code :

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:sap="http://www.sap.com/sapxsl"
  xmlns:asx="http://www.sap.com/abapxml"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;

<xsl:strip-space elements="*"/>

<xsl:template match="/">


<asx:abap version="1.0">
<asx:values>

 <xsl:for-each select="Document/pain.002.001.02">
<ACK_HEADER>
<ZTFI_PYSTATUS_HD>
  <xsl:for-each select="GrpHdr[1]">
  <ORGNLMSG_ID><xsl:value-of select="MsgId"/></ORGNLMSG_ID>
<!--  <MSG_CRTD_DATE><xsl:value-of select="CreDtTm"/></MSG_CRTD_DATE>-->
<xsl:variable name="date_time" select="CreDtTm"/>
<MSG_CRTD_DATE><xsl:value-of select="substring-before(@T,',$date_time')"/></MSG_CRTD_DATE>
<!--Payment Acknowledgement Header data-->
</xsl:for-each>

<xsl:for-each select="OrgnlGrpInfAndSts[1]">
<MSGID><xsl:value-of select="OrgnlMsgId"/></MSGID>
<xsl:variable name="msgid" select="OrgnlMsgId"/>
<ORIGNLMSG_NM_ID><xsl:value-of select="OrgnlMsgNmId"/></ORIGNLMSG_NM_ID>
<ORGNL_NO_OF_TRAN><xsl:value-of select="OrgnlNbOfTxs"/></ORGNL_NO_OF_TRAN>
<ORGNL_CNTRL_SUM><xsl:value-of select="OrgnlCtrlSum"/></ORGNL_CNTRL_SUM>
<ORGNL_FILE_STAT><xsl:value-of select="GrpSts"/></ORGNL_FILE_STAT>
<xsl:for-each select="NbOfTxsPerSts">
<xsl:choose>
<xsl:when test="DtldSts='ACSP'">
<ORGNL_NO_OF_ACSP><xsl:value-of select="DtldNbOfTxs"/></ORGNL_NO_OF_ACSP>
<ORGNL_ACSP_SUM><xsl:value-of select="DtldCtrlSum"/></ORGNL_ACSP_SUM>
</xsl:when>
<xsl:when test="DtldSts='RJCT'">
<ORGNL_NO_OF_RJCT><xsl:value-of select="DtldNbOfTxs"/></ORGNL_NO_OF_RJCT>
<ORGNL_RJCT_SUM><xsl:value-of select="DtldCtrlSum"/></ORGNL_RJCT_SUM>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</ZTFI_PYSTATUS_HD>
</ACK_HEADER>
<ACK_DETAIL>

<!--Payment Acknowledgement Detail data-->

<xsl:for-each select="TxInfAndSts">
<ZTFI_PYSTATUS_DT>
<MSGID><xsl:value-of select="$msgid"/></MSGID>
<PMT_INFO_IDENT><xsl:value-of select="OrgnlPmtInfId"/></PMT_INFO_IDENT>
<END_2_END_ID><xsl:value-of select="OrgnlEndToEndId"/></END_2_END_ID>
<TRAN_STATUS><xsl:value-of  select="TxSts"/></TRAN_STATUS>
<INSTRU_IDENT><xsl:value-of select="OrgnlInstrId"/></INSTRU_IDENT>
<xsl:for-each select="StsRsnInf[1]">
<STAT_RE_AD_INFO><xsl:value-of select="AddtlStsRsnInf"/></STAT_RE_AD_INFO>
</xsl:for-each>
<xsl:for-each select="OrgnlTxRef[1]">
<xsl:for-each select="Amt[1]">
<xsl:for-each select="InstdAmt[1]">
<INSTRCTD_AMT><xsl:value-of select="string()"/></INSTRCTD_AMT>
<CURRENCY><xsl:value-of select="@Ccy"/></CURRENCY>
</xsl:for-each>
</xsl:for-each>
<REQ_EXEC_DATE><xsl:value-of select="ReqdExctnDt"/></REQ_EXEC_DATE>
<xsl:for-each select="CdtrAcct[1]">
<xsl:for-each select="Id[1]">
<xsl:for-each select="PrtryAcct[1]">
<LIFNR><xsl:value-of select="Id"/></LIFNR>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>


</xsl:for-each>
</ZTFI_PYSTATUS_DT>
</xsl:for-each>
</ACK_DETAIL>
</xsl:for-each>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>

when i exclude the following string(in the Document tag) from the XML file i am able to transform.

'xmlns='urn:iso:std:iso:20022:tech:xsd:pain.002.001.02' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'&gt; 

but when i include the same string my XSLT transformation. it is not working.

Please do the needful.

Thanks and Regards, Kiran.

+1  A: 

Add your xml document namespace in your xsl declaration

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:sap="http://www.sap.com/sapxsl"
  xmlns:asx="http://www.sap.com/abapxml"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:doc='urn:iso:std:iso:20022:tech:xsd:pain.002.001.02'
>

and refer to your nodes by the prefix doc:. E.g:

<xsl:for-each select="doc:pain.002.001.02">

EDIT For your problem try:

<xsl:for-each select="doc:Document/doc:pain.002.001.02">
Gregoire
Hello Gregoire, Thank you for your quick response. i have changed the code, but still it is not working. Below is the change code : <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" xmlns:asx="http://www.sap.com/abapxml" xmlns:doc='urn:iso:std:iso:20022:tech:xsd:pain.002.001.02' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><xsl:for-each select="doc:Document/pain.002.001.02">Please help me out. Thanks and Regards,Kiran.
kiran puram
@kiran puram: see my edit
Gregoire
A: 

This is a FAQ. XPath treats unprefixed element names as belonging to "no namespace".

Whenever an XML document has a default namespace, the only way to refer to elements by name is to refer to them as prefixed, where the prefix is bound to the default namespace.

This means:

  1. Associate a prefix (say "xxx") to the document's default namespace.

  2. In any XPath expression or match pattern replace every element name by the corresponding preffixed name. For example, replace /a/b/c/d with /xxx:a/xxx:b/xxx:c/xxx:d

After following strictly the above two rules the modified stylesheet behaves as wanted: in the same way as the original stylesheet applied on an XML document that has no default namespace.

Dimitre Novatchev
Hello Dimitre Novatchev/Gregoire, it's resolved now.Thanks a ton for your quick help.Thanks and Regards, Regards,Kiran.
kiran puram
kiran-puram: Glad it's resolved. At StackOverflow (SO). the person who asked the qestion usually *accepts* one of the answers (by clicking on the check mark next to the answer). I believe you didn't know about that... :)
Dimitre Novatchev