xml - Chlid nodes is looped twice using XSLT -


i have input xml looks below:

<xml>  <form name ="vb.form" id ="form1" backcolor="&amp;h0080ff80&amp;" caption="form1" clientheight="7395" clientleft="120" clienttop="450" clientwidth="13815" linktopic="form1" scaleheight="7395" scalewidth="13815" startupposition="3  'windows default"> <picturebox name ="vb.picturebox" id ="picture2" height="975" left="4320" scaleheight="915" scalewidth="3675" tabindex="14" top="5880" width="3735"></picturebox> <frame name ="vb.frame" id ="frame1" backcolor="&amp;h00c0c0c0&amp;" caption="frame1" height="4095" left="840" tabindex="2" top="1560" width="11535"> <commandbutton name ="vb.commandbutton" id ="command2" caption="command2" height="375" left="720" tabindex="11" top="3480" width="1095"></commandbutton> <frame name ="vb.frame" id ="frame2" backcolor="&amp;h00e0e0e0&amp;" caption="frame2" height="3855" left="6720" tabindex="7" top="120" width="4695"> <label name ="vb.label" id ="label1" caption="this test of label" height="735" left="960" tabindex="8" top="840" width="1935"></label></frame> <picturebox name ="vb.picturebox" id ="picture1" backcolor="&amp;h00e0e0e0&amp;" height="2175" left="3600" scaleheight="2115" scalewidth="2835" tabindex="6" top="1560" width="2895"></picturebox> <combobox name ="vb.combobox" id ="combo1" height="315" left="3600" tabindex="5" text="combo1" top="1080" width="2655"></combobox> <listbox name ="vb.listbox" id ="list1" height="1425" left="600" tabindex="4" top="1200" width="2295"></listbox> <textbox name ="vb.textbox" id ="text2" height="615" left="600" tabindex="3" text="text2" top="480" width="2415"></textbox> <label name ="vb.label" id ="label3" caption="label3" height="255" left="5760" tabindex="10" top="240" width="615"></label> <shape name ="vb.shape" id ="shape1" height="615" left="4200" top="240" width="1095"></shape> <image name ="vb.image" id ="image1" height="3135" left="7200" top="480" width="3855"></image></frame> <textbox name ="vb.textbox" id ="text1" height="375" left="360" tabindex="1" text="text1" top="840" width="2535"></textbox> </form>  </xml> 

but getting below frames in child elements , cild elements under frames generated twice xslt:

<!doctype html system "about:legacy-compat"><html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <meta charset="utf-8">         <title>form1</title>     </head>     <body>         <div><canvas id="picture2" height="975" width="3735" style="position: absolute;padding-left:4320px;padding-top:5880px;"></canvas><div id="frame1" height="4095" width="11535" style="position: absolute;background:white;padding-left:840px;padding-top:1560px;"><div  id="command2" height="375" width="1095" style="position: absolute;padding-left:720px;padding-top:3480px;"><input type="submit" style="width:100%; height:100%;" value="submit" id="command2"/></div><div id="frame2" height="3855" width="4695" style="position: absolute;background:white;padding-left:6720px;padding-top:120px;"><label id="label1" height="735" width="1935" style="position: absolute;padding-left:960px;padding-top:840px;"></label></div><div id="frame2" height="3855" width="4695" style="position: absolute;background:white;padding-left:6720px;padding-top:120px;"><label id="label1" height="735" width="1935" style="position: absolute;padding-left:960px;padding-top:840px;"></label></div><canvas id="picture1" height="2175" width="2895" style="position: absolute;background:gray;padding-left:3600px;padding-top:1560px;"></canvas><div  id="combo1" height="315" width="2655" style="position: absolute;padding-left:3600px;padding-top:1080px;"><select multiple="multiple" id="combo1"/></div><div  id="list1" height="1425" width="2295" style="position: absolute;padding-left:600px;padding-top:1200px;"><select multiple="multiple" id="list1"/></div><div id="list1" height="1425" width="2295" style="position: absolute;padding-left:600px;padding-top:1200px;"></div><div  id="text2" height="615" width="2415" style="position: absolute;padding-left:600px;padding-top:480px;"><input type = "text" id = "mytext" style="width:100%; height:100%;" value = "text here" id="text2"/></div><label id="label3" height="255" width="615" style="position: absolute;padding-left:5760px;padding-top:240px;"></label><div id="shape1" height="615" width="1095" style="position: absolute;padding-left:4200px;padding-top:240px;"></div><img id="image1" height="3135" width="3855" style="position: absolute;padding-left:7200px;padding-top:480px;"></img></div><div id="frame1" height="4095" width="11535" style="position: absolute;background:white;padding-left:840px;padding-top:1560px;"><div  id="command2" height="375" width="1095" style="position: absolute;padding-left:720px;padding-top:3480px;"><input type="submit" style="width:100%; height:100%;" value="submit" id="command2"/></div><div id="frame2" height="3855" width="4695" style="position: absolute;background:white;padding-left:6720px;padding-top:120px;"><label id="label1" height="735" width="1935" style="position: absolute;padding-left:960px;padding-top:840px;"></label></div><div id="frame2" height="3855" width="4695" style="position: absolute;background:white;padding-left:6720px;padding-top:120px;"><label id="label1" height="735" width="1935" style="position: absolute;padding-left:960px;padding-top:840px;"></label></div><canvas id="picture1" height="2175" width="2895" style="position: absolute;background:gray;padding-left:3600px;padding-top:1560px;"></canvas><div  id="combo1" height="315" width="2655" style="position: absolute;padding-left:3600px;padding-top:1080px;"><select multiple="multiple" id="combo1"/></div><div  id="list1" height="1425" width="2295" style="position: absolute;padding-left:600px;padding-top:1200px;"><select multiple="multiple" id="list1"/></div><div id="list1" height="1425" width="2295" style="position: absolute;padding-left:600px;padding-top:1200px;"></div><div  id="text2" height="615" width="2415" style="position: absolute;padding-left:600px;padding-top:480px;"><input type = "text" id = "mytext" style="width:100%; height:100%;" value = "text here" id="text2"/></div><label id="label3" height="255" width="615" style="position: absolute;padding-left:5760px;padding-top:240px;"></label><div id="shape1" height="615" width="1095" style="position: absolute;padding-left:4200px;padding-top:240px;"></div><img id="image1" height="3135" width="3855" style="position: absolute;padding-left:7200px;padding-top:480px;"></img></div><div  id="text1" height="375" width="2535" style="position: absolute;padding-left:360px;padding-top:840px;"><input type = "text" id = "mytext" style="width:100%; height:100%;" value = "text here" id="text1"/></div></div>     </body> </html>          -------- 

my xslt looks this:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:output method="html" doctype-system="about:legacy-compat" encoding="utf-8" indent="yes" />     <xsl:variable name="vblookup" select="document('vblookup.xml')/vblookup"/>     <xsl:param name="list1" select="$vblookup/*"/>     <xsl:param name="list2" select="xml/form/*"/>     <xsl:param name="formname" select="xml/form/@name"/>      <xsl:template match="/">         <html>             <head>                 <meta charset="utf-8"/>                 <title><xsl:value-of select="xml/form/@caption"/></title>             </head>             <body>                 <xsl:call-template name="process-form"/>             </body>         </html>     </xsl:template>      <xsl:template name="process-form" match="form">         <xsl:for-each select="$vblookup/vbformobject">             <xsl:if test="@name=$formname">                 <xsl:element name="{@html5object}">                     <xsl:call-template name="process-children"/>                 </xsl:element>             </xsl:if>         </xsl:for-each>     </xsl:template>      <xsl:template name="process-children">         <xsl:for-each select="$list2">                 <xsl:call-template name="make-html-elements">                         <xsl:with-param name="name" select="@name"/>                         <xsl:with-param name="id1" select="@id"/>                         <xsl:with-param name="childnodes" select="child::node()"/>                 </xsl:call-template>              </xsl:for-each>     </xsl:template>        <xsl:template name="make-html-elements">         <xsl:param name="name" />         <xsl:param name="id1"/>         <xsl:param name="childnodes"/>         <xsl:for-each select="$list1">         <xsl:if test="@name=$name , not(contains(@html5object,'input')) , not(contains(@html5object,'select'))">                 <xsl:text disable-output-escaping="yes"><![cdata[<]]></xsl:text>                 <xsl:value-of select="@html5object"/>                  <xsl:text> id="</xsl:text><xsl:value-of select="$id1"/>                 <xsl:text>"</xsl:text>                 <xsl:text disable-output-escaping="yes"><![cdata[>]]></xsl:text>                 <xsl:for-each select="$childnodes">                     <xsl:variable name="fname" select="@name"/>                     <xsl:variable name="id" select="@id"/>                     <xsl:variable name="fchildnode" select="child::node()"/>                     <xsl:call-template name="make-html-elements">                         <xsl:with-param name="name" select="$fname"/>                         <xsl:with-param name="childnodes" select="$fchildnode"/>                 </xsl:call-template>                  </xsl:for-each>                 <xsl:text disable-output-escaping="yes"><![cdata[</]]></xsl:text>                 <xsl:value-of select="@html5object"/><xsl:text disable-output-escaping="yes"><![cdata[>]]></xsl:text>                 </xsl:if>             </xsl:for-each>     </xsl:template>  </xsl:stylesheet> 

the vlookup xml looks loke below:

<vblookup> <vbformobject name = ' vb.commandbutton' html5object='button' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'gray'/> <top html5='padding-top' default = '0'/> <width html5='width' default = '0'/><width html5='width' default = '0'/></properties>   </vbformobject>  <vbformobject name = 'vb.picturebox' html5object='canvas' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'gray'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject>  <vbformobject name = 'vb.listbox' html5object='select multiple="multiple"' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject>  <vbformobject name = 'vb.frame' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.checkbox' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.combobox' html5object='select multiple="multiple"' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.commandbutton' html5object='input type="submit" style="width:100%; height:100%;" value="submit"'>     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.data' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.dirlistbox' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.drivelistbox' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.filelistbox' html5object='div'  >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.form' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.frame' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.hscrollbar' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.image' html5object='img' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>           </vbformobject> <vbformobject name = 'vb.label' html5object='label' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.line' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.listbox' html5object='div'  >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.shape' html5object='div' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject> <vbformobject name = 'vb.textbox' html5object='input type = "text" id = "mytext" style="width:100%; height:100%;" value = "text here"' >     <properties>         <height html5='height' default = '0'/>         <left html5 = 'padding-left' default='0'/>         <backcolor html5 = 'background' default = 'white'/>             <top html5='padding-top' default = '0'/><width html5='width' default = '0'/></properties>            </vbformobject>  </vblookup> 

i not sure each executing twice generating child nodes twice incorrect. ant appreciated. in advance

i don't know why code doesn't want do. mentioned in comments, cannot reproduce result. suspect code complicated anyway - let me suggest simpler alternative:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html" doctype-system="about:legacy-compat" encoding="utf-8" indent="yes" /> <xsl:strip-space elements="*"/>  <xsl:param name="vblookup" select="document('vblookup.xml')"/>  <xsl:key name="map" match="vbformobject" use="@name" />  <!-- identity transform --> <xsl:template match="@*|node()">     <xsl:copy>         <xsl:apply-templates select="@*|node()"/>     </xsl:copy> </xsl:template>  <xsl:template match="/">     <html>         <head>             <meta charset="utf-8"/>             <title><xsl:value-of select="'put path title here'"/></title>         </head>         <body>             <xsl:apply-templates/>         </body>     </html> </xsl:template>  <!-- rename elements -->     <xsl:template match="*" priority="1">     <xsl:variable name="name">         <xsl:variable name="source-name" select="local-name()" />         <!-- switch context use key -->         <xsl:for-each select="$vblookup">             <xsl:variable name="target-name" select="key('map', $source-name)/@html5object" />             <xsl:choose>                 <xsl:when test="$target-name">                     <xsl:value-of select="$target-name"/>                 </xsl:when>                 <xsl:otherwise>                     <xsl:value-of select="$source-name"/>                 </xsl:otherwise>             </xsl:choose>         </xsl:for-each>     </xsl:variable>     <xsl:element name="{$name}">         <xsl:apply-templates select="@*|node()"/>     </xsl:element> </xsl:template>  </xsl:stylesheet> 

when applied input example (after correcting both xml files well-formed!), result is:

<!doctype html   system "about:legacy-compat"> <html>    <head>       <meta http-equiv="content-type" content="text/html; charset=utf-8">       <meta charset="utf-8">       <title>put path title here</title>    </head>    <body>       <div>          <div id="1"></div>          <c id="2">             <d id="3"></d>          </c>       </div>    </body> </html> 

if can every possible element in input xml has entry in lookup document, simplified further removing test.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -