Here is the XML i have, by applying xsl i want to insert a new node inside the elements/element node. See below the output im getting now and the expected output. also i m pasting the xsl i used to get the nodes as output. Please provide a chaneg to the xsl so tht it can insert a new node and display the same in the hierachy.
Please provide your valuable inputs.
XML:
<?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="MD4" 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 for plans with fundingArrangement: Fully 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:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml" />
<xsl:strip-space elements="*" />
<xsl:template match="*[*]">
<xsl:copy>
<xsl:apply-templates select="*[*]" />
</xsl:copy>
</xsl:template>
<xsl:template match="@*|elements/*">
<xsl:copy>
<reference>
<xsl:apply-templates select="@*|elements/child::*"/>
</reference>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Output:
<plans xmlns="http://hphc.org/schema/product/v1">
<plan>
<ids/>
<planInfo>
<productInfo>
<items/>
<indicators/>
<versionInfo/>
</productInfo>
<forms>
<form>
<items/>
</form>
<form/>
</forms>
<networks>
<network/>
</networks>
</planInfo>
<elements>
<element>
<indicators/>
</element>
</elements>
</plan>
</plans>
Expected Output:
<elements>
<element>
<indicators/>
-- new node-- <reference/> -- new node--
</element>
</elements>
As long as your template match refers to wildcards like
*
:you do not have to worry about namespaces. However, if you match specific elements from your input XML like here:
you have to adhere to the default namespace specified. The following line defines a default namespace:
which is passed on to all child elements as well. In other words, the
element
element has a namespace, too. As far as the XSLT processor is concerned,v1:element
andelement
are entirely different elements.By the way,
@*
) because they are not matched anyway.elements
elements) an expression likeelements/child::*"
selects all children of the children of a child of anelements
element that are called "elements". Which is confusing and not what you want, I think.Stylesheet
Output