I am new to XSLT. The requirement i have is to convert an XML to another XML format.
My source XML looks something like:
<QryLMLCheck>
<RequestingSystemID>{3644ACD2-5A36-4B4D-876C-7A9C3E77CFAD}</RequestingSystemID>
<PolicyNumber>0003036517</PolicyNumber>
<PolicyEffectiveDate>2006-11-15T00:00:00</PolicyEffectiveDate>
<ReportType>Renewal</ReportType>
<PartyID>590005484</PartyID>
<CompanyName>TI Automotive, Ltd.</CompanyName>
<CompanyDBA></CompanyDBA>
<ProducerCode>18232000</ProducerCode>
<AgencyName>Marsh USA, Inc.</AgencyName>
<AgencyDBAName></AgencyDBAName>
<AgencyAddress1>1166 Avenue of the Americas</AgencyAddress1>
<AgencyAddress2></AgencyAddress2>
<AgencyAddress3></AgencyAddress3>
<AgencyCity>New York</AgencyCity>
<AgencyStateProvince>NY</AgencyStateProvince>
<AgencyPostalCode>10036</AgencyPostalCode>
<Address1>12345 E Nine Mile Rd</Address1>
<Address2></Address2>
<Address3></Address3>
<City>Warren</City>
<StateProvince>MI</StateProvince>
<PostalCode>48090</PostalCode>
<OriginalSICCode>3317</OriginalSICCode>
<OriginalSICDescription></OriginalSICDescription>
<IsPrimary>1</IsPrimary>
<LOB>Auto</LOB>
</QryLMLCheck>
XSLT i developed is:
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:output name="out" method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="//QryLMLCheck">
<xsl:choose>
<xsl:when test="count (for $a in preceding-sibling::node() return for $b in ProducerCode return $a[ProducerCode=$b]) = 0">
<xsl:variable name="ProCode" select="ProducerCode"/>
<xsl:result-document href="'{$ProCode}.xml'" format="out">
<xsl:element name="VCResult">
<RequesterID><xsl:value-of select="RequestingSystemID"/></RequesterID>
<PolicyNumber><xsl:value-of select="PolicyNumber"/></PolicyNumber>
<PolicyEffectiveDate><xsl:value-of select="PolicyEffectiveDate"/></PolicyEffectiveDate>
<TransactionType><xsl:value-of select="ReportType"/></TransactionType>
<CMSPartyID><xsl:value-of select="PartyID"/></CMSPartyID>
<Name><xsl:value-of select="CompanyName"/></Name>
<DBName><xsl:value-of select="CompanyDBA"/></DBName>
<Agency>
<ProducerCode><xsl:value-of select="ProducerCode"/></ProducerCode>
<Name><xsl:value-of select="AgencyName"/></Name>
<DBAName><xsl:value-of select="AgencyDBAName"/></DBAName>
<Address1><xsl:value-of select="AgencyAddress1"/></Address1>
<Address2><xsl:value-of select="AgencyAddress2"/></Address2>
<Address3><xsl:value-of select="AgencyAddress3"/></Address3>
<City><xsl:value-of select="AgencyCity"/></City>
<StateProvince><xsl:value-of select="AgencyStateProvince"/></StateProvince>
<PostalCode><xsl:value-of select="AgencyPostalCode"/></PostalCode>
</Agency>
<Locations>
<xsl:for-each select="for $a in //QryLMLCheck return for $b in . return $a[ProducerCode=$b/ProducerCode]">
<xsl:choose>
<xsl:when test="count( for $a in preceding-sibling::node() return for $b in . return $a[Address1=$b/Address1][Address2=$b/Address2] )=0">
<location>
<Address1><xsl:value-of select="Address1"/></Address1>
<Address2><xsl:value-of select="Address2"/></Address2>
<Address3><xsl:value-of select="Address3"/></Address3>
<City><xsl:value-of select="City"/></City>
<StateProvince><xsl:value-of select="StateProvince"/></StateProvince>
<PostalCode><xsl:value-of select="PostalCode"/></PostalCode>
<SICCode><xsl:value-of select="OriginalSICCode"/></SICCode>
<SICDescription><xsl:value-of select="OriginalSICDescription"/></SICDescription>
<LOBS>
<xsl:for-each select="for $a in //QryLMLCheck return for $b in . return $a[Address1=$b/Address1][Address2=$b/Address2]">
<lob>
<xsl:value-of select="LOB"/>
</lob>
</xsl:for-each>
</LOBS>
<Primary><xsl:value-of select="IsPrimary"/></Primary>
</location>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</Locations>
</xsl:element>
</xsl:result-document>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
While i try to run this XSLT i am getting "xpath" error in
<xsl:when test="count (for $a in preceding-sibling::node() return for $b in ProducerCode return $a[ProducerCode=$b]) = 0">
and all the places where i defined in same way...
please can someone help me in this case..
Thanks
Kannan