xml - To select element with multiple Namespaces on an element with XSLT 1.0/2.0 -


i have input xml has elements multiple namespaces, need transform input xml xml format. not sure how specifiy multiple namespaces in xpath select value of element avresult has 2 namespaces "a" , "i"

<?xml version="1.0" encoding="utf-8"?> <s:envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"     xmlns:u="http://docs.oasis-open.org/2004/01/ty.xsd">     <s:header>      </s:header>     <s:body>         <avresponse             xmlns="http://info.com/contracts">             <avresult                 xmlns:a="http://namespaceone.com"                 xmlns:i="http://namespacetwo.com">                 <errors                     xmlns="http://schemas.messages" />                 <errordetail>                     <code>1718</code>                     <description>con types: sum should equal 100%</description>                 </errordetail>                 <status xmlns="http://schemas.basemessages">success</status>                 <a:newid>275373</a:newid>                 <a:valn>                     <a:locs>                         <a:loc>                             <a:builds>                                 <a:build>                                     <a:totals>                                         <a:rcv>11430888.8146038</a:rcv>                                     </a:totals>                                 </a:build>                             </a:builds>                         </a:loc>                     </a:locs>                 </a:valn>             </avresult>         </avresponse>     </s:body> </s:envelope> 

here xslt:

<xsl:stylesheet version="2.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:soap="http://www.w3.org/2003/05/soap-envelope"     xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:fo="http://service.fo.com/"     xmlns:ns1="http://info.com/contracts"      xmlns:a="http://namespaceone.com"     xmlns:ns3="http://schemas.basemessages"     xmlns:i="http://namespacetwo.com"     exclude-result-prefixes="ns1 s">      <xsl:output method="xml" />     <xsl:strip-space elements="*" />      <xsl:template match="/">         <xsl:apply-templates select="*"/>     </xsl:template>     <xsl:template match="s:header">      </xsl:template>      <xsl:template match="s:body/ns1:avresponse">         <xsl:apply-templates select="@* | node()" />    </xsl:template>    <xsl:template match="a:avresult">          <builds>             <response-header>                 <fo:response-messages>                      <xsl:if                         test="//status='success'">                         <fo:response-message>                             <fo:response-type>status</fo:response-type>                             <fo:response-code></fo:response-code>                             <fo:response-description>                                 <xsl:value-of select="//avresponse/avresult/status" />                             </fo:response-description>                         </fo:response-message>                     </xsl:if>                     <xsl:if test="//avresponse/avresult/status='error'">                         <fo:response-message>                             <fo:response-type>status</fo:response-type>                             <fo:response-code></fo:response-code>                             <fo:response-description>                                 <xsl:value-of                                     select="//ns1:avresponse/a:avresult/ns3:status" />                             </fo:response-description>                         </fo:response-message>                         <xsl:for-each                             select="//ns1:avresponse/ns1:avresult/ns3:errors">                             <fo:response-message>                                 <fo:response-type>                                     <xsl:value-of                                         select="//ns1:avresponse/ns1:avresult/ns3:errors/ns3:errordetail">                                     </xsl:value-of>                                 </fo:response-type>                                 <fo:response-code>                                     <xsl:value-of                                         select="//ns1:avresponse/ns1:avresult/ns3:errors/ns3:errordetail/ns3:code">                                     </xsl:value-of>                                 </fo:response-code>                                 <fo:response-description>                                     <xsl:value-of                                         select="//ns1:avresponse/ns1:avresult/ns3:errors/ns3:errordetail/ns3:description">                                     </xsl:value-of>                                 </fo:response-description>                             </fo:response-message>                         </xsl:for-each>                     </xsl:if>                 </fo:response-messages>             </response-header>             <!--<xsl:for-each select="//a:locs/a:loc"> -->             <build>                 <property>                     <fo:itv-output>                         <fo:estimated-construction-amt>                             <fo:amount>                                 <xsl:value-of                                     select="//ns1:avresponse/ns1:avresult/a:locs/a:loc/a:builds/a:build/a:totals/a:rcv">                                 </xsl:value-of>                             </fo:amount>                             <fo:currency>usd</fo:currency>                         </fo:estimated-construction-amt>                     </fo:itv-output>                 </property>             </build>             <!-- </xsl:for-each> -->         </builds>      </xsl:template> </xsl:stylesheet> 

here, how include 2 namespace select avresult ?

avresult has 3 namespaces. takes on namespace parent node avresponse (xmlns="http://info.com/contracts"). but, since namespace avresponse not have prefix, have create reference prefix in stylesheet tag, created ns1. so, time want reference avresponse or of it's child or grandchild nodes have use ns1 prefix. also, can't put ns1 in exclude-result-prefixes , exclude it.

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"  xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"  xmlns:fo="http://service.fo.com/" xmlns:ns1="http://info.com/contracts"  xmlns:a="http://namespaceone.com" xmlns:ns3="http://schemas.basemessages" xmlns:i="http://namespacetwo.com" exclude-result-prefixes="ns3 s b">   <xsl:template match="ns1:avresult">     stuff </xsl:template> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -