473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XSLT Xpath query

1 New Member
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 1819
dorinbogdan
839 Recognized Expert Contributor
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 Recognized Expert Contributor
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

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

Similar topics

1
by: inquirydog | last post by:
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt? document("document.xml")//a/@b For the...
7
by: mike p. | last post by:
I have a docbook xml file, and am using standard docbook 1.61.3 xsl stylesheets to do xhtml transform. Transform works fine when using MSXML. When I try to do the following using asp.net 1.1: ...
1
by: jrwarwick | last post by:
Hello, I believe I have uncovered a bug in the .Net XSLT engine to do with 'for' loops in XSLT. Here are the steps to reproduce it: -Create A new webform project. -Add the xml file...
3
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION>...
3
by: Greg | last post by:
Hi, I want to create a web based interface that uses a form + Javascript (in an XHTML namespace) to construct an XPath to query and modify the attributes of some SVG (in an SVG namespace). ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.