xml - Using XSLT insert a new node with hyperlink -


im new xsl. here xml have, applying xsl want insert new node inside elements/element node. see below output im getting , expected output. m pasting xsl used nodes output. please provide change xsl can insert new node , display same in hierarchy.

please provide valuable inputs.

<?xml version="1.0" encoding="utf-8"?> <plans xmlns="http://test.org/schema/product/v1"> <plan effdate="2013-07-01" enddate="9999-12-31" id="md0000002524" source="pdm" state="released" version="i.8" vertical="medical">     <!--generated by: generatepdmcanonical ver. 16.4-->     <!--codeset version 1.6-->     <!--generated by: filterpdm ver. 8-->     <ids windchill="md0000002524">         <id type="windchill">1</id>         <id type="boc">1</id>     </ids>     <planinfo>         <productinfo source="pdm">             <claimadjudicationbegindate>2013-07-01</claimadjudicationbegindate>             <items>                 <!--unmapped items-->                 <item name="baselineid">000000</item>             </items>             <indicators>                 <indicator type="hsaqualified">false</indicator>                 <!--unmapped indicators-->                 <indicator type="hsaqualified">false</indicator>             </indicators>             <versioninfo>                 <version>i</version>             </versioninfo>         </productinfo>         <forms>             <form id="fr0000001378" type="filingform" version="a.1">                 <formtype>ma ppo</formtype>                 <legalentity>company</legalentity>                 <ratingstate>ma</ratingstate>                 <items>                     <!--unmapped items-->                     <item name="contentbaselinenumber"/>                 </items>             </form>             <form id="1379" type="handbookform" version="a.1">                 <formtype>fully insured</formtype>                 <formnumber/>             </form>         </forms>         <!--plan level networks-->         <networks id="plan">             <network id="nt0300000029" name="tier 3" version="a.1">                 <networkcode>029</networkcode>                 <networkname>tier 3</networkname>                 <networktype>in</networktype>                 <networklevel>3</networklevel>             </network>         </networks>     </planinfo>     <elements>         <!--plan-level deductibles-->         <element id="bn000001" parent="bn09" type="" version="a.3">             <forservice>breast </forservice>             <elementvalue forservice="breast "/>             <!--defined plans fundingarrangement: insured-->             <indicators>                 <indicator type="referralrequired">false</indicator>                 <indicator type="payalways">false</indicator>             </indicators>             <networks ref="plan"/>             <defaultcmslocation>12</defaultcmslocation>             <!--costshare applies:applycoinsurance|applydeductible|applyooncoins|applyoondeductible|applytooopmax-->             <element name="20% 1" networktype="in" ref="c005" type="coinsurance" version="a.7"/>             <element name="$1000 in -  tier 1" networktype="in" ref="dd0" type="deductible" version="b.2"/>         </element>     </elements> </plan> 

xsl: display nodes hyperlink

    <?xml version="1.0"?>     <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">  <xsl:template match="/">   <div class="l-d">     <xsl:apply-templates/>   </div> </xsl:template>  <xsl:template match="text()"/>  <xsl:template match="*[*]">         <div class="l-d-t1">             <div class="l-d-t1-t2">                 <a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a>         <span class="l-d-t1-t2-s-xpath"><xsl:for-each select="ancestor::*">/<xsl:value-of select="name(.)"/>[<xsl:value-of select="count(preceding-sibling::*[name()=name(current())])+1"/>]</xsl:for-each>/<xsl:value-of select="name(.)"/>[<xsl:value-of select="count(preceding-sibling::*[name()=name(current())])+1"/>]</span>                 <span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">                     <xsl:value-of select="name()"/>                 </span>             </div>             <xsl:apply-templates/>         </div> </xsl:template>   </xsl:stylesheet> 

actual output:

<?xml version="1.0" encoding="utf-8"?><div class="l-d"><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">plans</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">plan</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/ids[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">ids</span></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">planinfo</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/productinfo[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">productinfo</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/productinfo[1]/items[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">items</span></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/productinfo[1]/indicators[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">indicators</span></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/productinfo[1]/versioninfo[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">versioninfo</span></div></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/forms[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">forms</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/forms[1]/form[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">form</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/forms[1]/form[1]/items[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">items</span></div></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/forms[1]/form[2]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">form</span></div></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">networks</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[1]/network[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">network</span></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[1]/network[2]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">network</span></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[1]/network[3]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">network</span></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[1]/network[4]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">network</span></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[1]/network[5]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">network</span></div></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[2]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">networks</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[2]/network[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">network</span></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/planinfo[1]/networks[2]/network[2]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">network</span></div></div></div></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/elements[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">elements</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/elements[1]/element[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">element</span></div><div class="l-d-t1"><div class="l-d-t1-t2"><a href="#" onclick="f_l_nav(this);" class="l-d-t1-t2-a">-</a><span class="l-d-t1-t2-s-xpath">/plans[1]/plan[1]/elements[1]/element[1]/indicators[1]</span><span class="l-d-t1-t2-s-name" onclick="f_l_nav(this,1);">indicators</span></div></div></div></div></div></div></div> 

expected output:

-/plans[1]plans-/plans[1]/plan[1]plan-/plans[1]/plan[1]/ids[1]ids-/plans[1]/plan[1]/planinfo[1]planinfo-/plans[1]/plan[1]/planinfo[1]/productinfo[1]productinfo-/plans[1]/plan[1]/planinfo[1]/productinfo[1]/items[1]items-/plans[1]/plan[1]/planinfo[1]/productinfo[1]/indicators[1]indicators-/plans[1]/plan[1]/planinfo[1]/productinfo[1]/versioninfo[1]versioninfo-/plans[1]/plan[1]/planinfo[1]/forms[1]forms-/plans[1]/plan[1]/planinfo[1]/forms[1]/form[1]form-/plans[1]/plan[1]/planinfo[1]/forms[1]/form[1]/items[1]items-/plans[1]/plan[1]/planinfo[1]/forms[1]/form[2]form-/plans[1]/plan[1]/planinfo[1]/networks[1]networks-/plans[1]/plan[1]/planinfo[1]/networks[1]/network[1]network-/plans[1]/plan[1]/planinfo[1]/networks[1]/network[2]network-/plans[1]/plan[1]/planinfo[1]/networks[1]/network[3]network-/plans[1]/plan[1]/planinfo[1]/networks[1]/network[4]network-/plans[1]/plan[1]/planinfo[1]/networks[1]/network[5]network-/plans[1]/plan[1]/planinfo[1]/networks[2]networks-/plans[1]/plan[1]/planinfo[1]/networks[2]/network[1]network-/plans[1]/plan[1]/planinfo[1]/networks[2]/network[2]network-/plans[1]/plan[1]/elements[1]elements-/plans[1]/plan[1]/elements[1]/element[1]element-/plans[1]/plan[1]/elements[1]/element[1]/indicators[1]indicators-/plans[1]/plan[1]/elements[1]/element[1]/reference[1]reference<

you can way: copy every node other elements/element/element. , create reference , put elements/element/element in it:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:pre="http://test.org/schema/product/v1" exclude-result-prefixes="pre"> <xsl:output method="xml" indent="yes"/>  <xsl:template match="node() | @*">     <xsl:copy>         <xsl:apply-templates select="node() | @*"/>     </xsl:copy> </xsl:template>  <xsl:template match="pre:elements/pre:element">     <xsl:copy>         <xsl:apply-templates select="node()[not(local-name() = 'element')] | @*"/>         <pre:reference>                 <xsl:copy-of select="pre:element"/>         </pre:reference>     </xsl:copy> </xsl:template> </xsl:stylesheet> 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -