parsing - XSLT- Pre Define NameSpace -


hi have xml upon each delivery has different unique named namespace cannot pre determine standard processes.

<abc xmlns:this="urn:uuid:9b1f15a9-69de-11d2-b6bc-fcab70ff7331" version="1.1"> <extensions>   <identification>urn:uuid:9b1f15a9-69de-11d2-b6bc-fcab70ff7331</identification>   <extension>     <srcpackage>         <this:abdlist>           <taggedvalue>111</taggedvalue>         </this:abdlist>         <this:subbegin>0</this:subbegin>     </srcpackage>     <matpackage>         <this:abdlist>           <taggedvalue>222</taggedvalue>         </this:abdlist>         <this:subbegin>1</this:subbegin>     </matpackage>     <!-- stuff -->   </extention> </extentions> </abc> 

the next xml delivered

<abc xmlns:this="urn:uuid:9b1ffae4-69de-11d2-b6bc-fcab70ff7331" version="1.1"> <extensions>   <identification>urn:uuid:9b1ffae4-69de-11d2-b6bc-fcab70ff7331</identification>   <extension>     <srcpackage>         <this:abdlist>           <taggedvalue>333</taggedvalue>         </this:abdlist>         <this:subbegin>0</this:subbegin>     </srcpackage>     <matpackage>         <this:abdlist>           <taggedvalue>444</taggedvalue>         </this:abdlist>         <this:subbegin>1</this:subbegin>     </matpackage>     <!-- stuff -->   </extention> </extentions> </abc> 

my current xsl stylesheet works on first xml predefining namespace looking find way re-define later on. on process. have added variable pull relevant uuid identification element not sure how integrate this. using below stylesheet process other xml results in false results.

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:this="urn:uuid:9b1f15a9-69de-11d2-b6bc-fcab70ff7331" xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext"> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" /> <xsl:strip-space elements="*"/>  <xsl:variable name="selopgroup" select="/abc/extensions/identification"/>  <!-- pass thru  ---> <xsl:template match="@*|node()"> <xsl:copy>     <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>  <xsl:template match="/abc/extensions/srcpackage>   <xsl:copy>             <this:abdlist>                 <xsl:copy-of select ="this:abdlist/*"/>                 <taggeda>888</taggeda>             </this:abdlist>             <this:subbegin><xsl:value-of select="somethingelse"/> </this:subbegin>   </xsl:copy> </xsl:template>  <xsl:template match="/abc/extensions/matpackage>   <xsl:copy>             <this:abdlist>                 <xsl:copy-of select ="this:abdlist/*"/>                 <taggedb>999</taggedb>             </this:abdlist >             <this:subbegin><xsl:value-of select="somethingelse"/> </this:subbegin>   </xsl:copy> </xsl:template> </xsl:stylesheet> 

expected result

<abc xmlns:this="urn:uuid:9b1ffae4-69de-11d2-b6bc-fcab70ff7331" version="1.1"> <extensions>   <identification>urn:uuid:9b1ffae4-69de-11d2-b6bc-fcab70ff7331</identification>   <extension>     <srcpackage>         <this:abdlist>           <taggedvalue>333</taggedvalue>           <taggeda>888</taggeda>         </this:abdlist>         <this:subbegin>a value</this:subbegin>     </srcpackage>     <matpackage>         <this:abdlist>           <taggedvalue>444</taggedvalue>           <taggedb>999</taggeda>         </this:abdlist>         <this:subbegin>a value</this:subbegin>     </matpackage>     <!-- stuff -->   </extention> </extentions> </abc> 

many thanks, adrian

this transformation:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />   <xsl:strip-space elements="*"/>    <xsl:variable name="selopgroup" select="/abc/extensions/identification"/>    <!-- pass thru  -->   <xsl:template match="@*|node()">     <xsl:copy>       <xsl:apply-templates select="@*|node()"/>     </xsl:copy>   </xsl:template>    <xsl:template match="extension/srcpackage">     <xsl:copy>             <xsl:element name="{'this:abdlist'}" namespace="{$selopgroup}">                 <xsl:copy-of select="/*/namespace::*[name()='this']"/>                 <xsl:copy-of select ="*[name() = 'this:abdlist']/*"/>                 <taggeda>888</taggeda>             </xsl:element>             <xsl:element name="{'this:subbegin'}" namespace="{$selopgroup}">                 <xsl:copy-of select="/*/namespace::*[name()='this']"/>                 <xsl:value-of select="'somethingelse'"/>             </xsl:element>     </xsl:copy>   </xsl:template>    <xsl:template match="extension/matpackage">     <xsl:copy>             <xsl:element name="{'this:abdlist'}" namespace="{$selopgroup}">                 <xsl:copy-of select="/*/namespace::*[name()='this']"/>                 <xsl:copy-of select ="*[name() = 'this:abdlist']/*"/>                 <taggedb>999</taggedb>             </xsl:element>             <xsl:element name="{'this:subbegin'}" namespace="{$selopgroup}">                 <xsl:copy-of select="/*/namespace::*[name()='this']"/>                 <xsl:value-of select="'somethingelse'"/>             </xsl:element>     </xsl:copy>   </xsl:template> </xsl:stylesheet> 

when applied on first provided xml document:

<abc xmlns:this="urn:uuid:9b1f15a9-69de-11d2-b6bc-fcab70ff7331" version="1.1">     <extensions>         <identification>urn:uuid:9b1f15a9-69de-11d2-b6bc-fcab70ff7331</identification>         <extension>             <srcpackage>                 <this:abdlist>                     <taggedvalue>111</taggedvalue>                 </this:abdlist>                 <this:subbegin>0</this:subbegin>             </srcpackage>             <matpackage>                 <this:abdlist>                     <taggedvalue>222</taggedvalue>                 </this:abdlist>                 <this:subbegin>1</this:subbegin>             </matpackage>             <!-- stuff -->         </extension>     </extensions> </abc> 

produces wanted, correct result:

<abc xmlns:this="urn:uuid:9b1f15a9-69de-11d2-b6bc-fcab70ff7331" version="1.1">    <extensions>       <identification>urn:uuid:9b1f15a9-69de-11d2-b6bc-fcab70ff7331</identification>       <extension>          <srcpackage>             <this:abdlist>                <taggedvalue>111</taggedvalue>                <taggeda>888</taggeda>             </this:abdlist>             <this:subbegin>somethingelse</this:subbegin>          </srcpackage>          <matpackage>             <this:abdlist>                <taggedvalue>222</taggedvalue>                <taggedb>999</taggedb>             </this:abdlist>             <this:subbegin>somethingelse</this:subbegin>          </matpackage><!-- stuff -->       </extension>    </extensions> </abc> 

when same transformation applied on second provided xml document:

<abc xmlns:this="urn:uuid:9b1ffae4-69de-11d2-b6bc-fcab70ff7331" version="1.1"> <extensions>   <identification>urn:uuid:9b1ffae4-69de-11d2-b6bc-fcab70ff7331</identification>   <extension>     <srcpackage>         <this:abdlist>           <taggedvalue>333</taggedvalue>         </this:abdlist>         <this:subbegin>0</this:subbegin>     </srcpackage>     <matpackage>         <this:abdlist>           <taggedvalue>444</taggedvalue>         </this:abdlist>         <this:subbegin>1</this:subbegin>     </matpackage>     <!-- stuff -->   </extension> </extensions> </abc> 

again wanted, correct result produced:

<abc xmlns:this="urn:uuid:9b1ffae4-69de-11d2-b6bc-fcab70ff7331" version="1.1">    <extensions>       <identification>urn:uuid:9b1ffae4-69de-11d2-b6bc-fcab70ff7331</identification>       <extension>          <srcpackage>             <this:abdlist>                <taggedvalue>333</taggedvalue>                <taggeda>888</taggeda>             </this:abdlist>             <this:subbegin>somethingelse</this:subbegin>          </srcpackage>          <matpackage>             <this:abdlist>                <taggedvalue>444</taggedvalue>                <taggedb>999</taggedb>             </this:abdlist>             <this:subbegin>somethingelse</this:subbegin>          </matpackage><!-- stuff -->       </extension>    </extensions> </abc> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -