469,330 Members | 1,288 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

XSLT Xpath query

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
Feb 7 '07 #1
2 1614
dorinbogdan
839 Expert 512MB
It seems strange the combination between "count" and "for" :
count(for ...return for ...return)

Also, if put $a between paranthesis as in:
<xsl:when test="count(for ($a) in preceding-sibling::node() .....

I get the error:
'for' is not a valid XSLT or XPath function.

We should try to find a solution without using for...

I'll continue to search too.
Please let me know if you find one.
Feb 15 '07 #2
dorinbogdan
839 Expert 512MB
Hi,
Did you succeed to solve the problem ?
If yes, please let me know, in order to close the thread.
Thanks,
Dorin.
Mar 21 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.