Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 26th, 2010, 12:17 PM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL Loop with counter and concat

I have the following code defined to make generic translation based on different set of files.

I have 60 different objects coming in same XML format. I would like to build one map for all.

Creating all the variables for each object type where the values are going to be the attribute, based on variable value, we need to find other values and write to the target. For all object types, the variable names are going to be the same.

I think i am having trouble with having loop for each object type, because the number of attributes are different from each other. So i have given number fields as counter, then trying to loop through.

Also the following syntax, i am trying to concat text and counter, and pass as field name, i am not sure whether it will work or not. but in debug mode, i am able to to see VAR1. but at runtime, i am unable to change the counter


<xsl:variable name="before" select="$attrList[substring-before($Comp[concat('var',$counter)],',')]"/>

any help is appreciated

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xsl">

	<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>

	<xsl:template match="/">
		<xsl:for-each select="/ematrix/businessObject">
			<xsl:variable name="bO" select="./objectType"/>
			<xsl:variable name="Comp">
				<xsl:choose>
					<xsl:when test="$bO = 'MPG Complaint'">
						<count>61</count>
						<var1>MPG Complaint Priority,string</var1>
						<var2>MPG Complaint Complainant Requested Reply,boolean</var2>
						<var3>Complaint Originator,string</var3>
						<var4>Complaint Source,string</var4>
						<var5>Complaint Reportable Complaint,string</var5>
						<var6>Complaint Date Closed,datetime,string</var6>
						<var7>Complaint External Reference,string</var7>
						<var8>Complaint Clinical Trial Complaint,string</var8>
						<var9>Complaint Customer Compensation Method,string</var9>
						<var10>Complaint Litigation,string</var10>
						<var11>Complaint Compensation Details,string</var11>
						<var12>Complaint Invalidator,string</var12>
						<var13>Complaint Invalidated Date,datetime,string</var13>
						<var14>Complaint Invalid Rationale,string</var14>
						<var15>MPG Complaint Country of Origin,string</var15>
						<var16>MPG Purchase Order Number,string</var16>
						<var17>Originated,datetime,string</var17>
						<var18>MPG Complaint Customer Closure,datetime</var18>
						<var19>MPG Complaint Quality Closure,datetime</var19>
						<var20>MPG Complaint Medical Closure,datetime</var20>
						<var21>MPG Complaint TPM Notification Date,datetime</var21>
						<var22>MPG Complaint Medical,boolean</var22>
						<var23>MPG Complaint KANA Number,string</var23>
						<var24>MPG Complaint Affiliate QA Number,string</var24>
						<var25>MPG Complaint Affiliate Tracking Number,string</var25>
						<var26>AN Complaint Affiliate Country,string</var26>
						<var27>AN Complaint Affiliate Responsible Person,string</var27>
						<var28>AN Complaint Affiliate Cross Reference Number,string</var28>
						<var29>AN Complaint Affiliate Classification,string</var29>
						<var30>MPG Complaint Report Sources,string</var30>
						<var31>AN Complaint Where Purchased,string</var31>
						<var32>Complaint Product Type,string</var32>
						<var33>ADD Complaint Ready For Close,string</var33>
						<var34>ADD Complaint Quality Directive,string</var34>
						<var35>ADD pRE Questions,string</var35>
						<var36>type,string</var36>
						<var37>MPG Complaint Division,string</var37>
						<var38>MPG Complaint MDC Modified Date,datetime</var38>
						<var39>MPG Complaint Meaningful Data Change,string</var39>
						<var40>MPG Complaint Abbott Awareness Date,datetime</var40>
						<var41>MPG Complaint Notes,string</var41>
						<var42>MPG Complaint Version Number,string</var42>
						<var43>AN ComplaintMarketing Program Number,string</var43>
						<var44>name,string</var44>
						<var45>Related Ticket,string</var45>
						<var46>Reply Expectation,string</var46>
						<var47>Customer Follow-up Notes,string</var47>
						<var48>Field Action Number,string</var48>
						<var49>Issue Bucket,string</var49>
						<var50>Experience Bucket,string</var50>
						<var51>Delayed Entry Justification,string</var51>
						<var52>Error Codes,string</var52>
						<var53>Technical Service Bulletin,string</var53>
						<var54>MPG Complaint Type Change Justification,string</var54>
						<var55>Customer follow-up mode,string</var55>
						<var56>Follow-up Status,string</var56>
						<var57>MPG Complaint Quality Followup Assignee,string</var57>
						<var58>MPG Complaint MDC Medical,string</var58>
						<var59>MPG Complaint MDC Quality,string</var59>
						<var60>MPG Complaint MDC Regulatory,string</var60>
						<var61>sourcefilename,string</var61>
					</xsl:when>
				</xsl:choose>
			</xsl:variable>

			<xsl:call-template name="attrout">
				<xsl:with-param name="counter" select="1"/>
				<xsl:with-param name="varCount" select="$Comp/count"/>
			</xsl:call-template>
			<xsl:variable name="attrList" select="attributeList/attribute"/>

		</xsl:for-each>
	</xsl:template>
				<xsl:template name="attrout">
				<xsl:param name="counter"/>
				<xsl:param name="varCount"/>

				<xsl:if test="$counter &lt; $varCount">

					<xsl:choose>
						<xsl:when test="$bO = 'MPG Complaint'">
							<xsl:variable name="before" select="concat('var',$counter)"/>
							<xsl:variable name="after" select="$attrList[substring-after($Comp[concat('var',$counter)],',')]"/>

							<xsl:choose>
								<xsl:when test="$after = 'string'">
									<xsl:value-of select="$attrList[name=$before]/string"/>
								</xsl:when>
								<xsl:when test="$after = 'datetime'">
									<xsl:value-of select="$attrList[name=$before]/datetime"/>
								</xsl:when>
								<xsl:when test="$after = 'boolean'">
									<xsl:value-of select="$attrList[name=$before]/boolean"/>
								</xsl:when>
							</xsl:choose>

							<xsl:call-template name="attrout">
								<xsl:with-param name="counter" select="$counter + 1"/>
							</xsl:call-template>
						</xsl:when>
					</xsl:choose>
				</xsl:if>
			</xsl:template>

</xsl:stylesheet>
Reply With Quote
  #2 (permalink)  
Old July 26th, 2010, 12:58 PM
mhkay's Avatar
Wrox Author
Points: 18,420, Level: 59
Points: 18,420, Level: 59 Points: 18,420, Level: 59 Points: 18,420, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,952
Thanks: 0
Thanked 289 Times in 284 Posts
Default

You've described your problem in very procedural terms (i.e. you've described your attempted solution, not the problem). And I'm having trouble seeing what you're trying to achieve. There are some obvious things wrong at the coding level, for example having an xsl:variable as the last thing in an xsl:for-each makes no sense, because the variable is only accessible to subsequent instructions in the body of the same xsl:for-each. Your only reference to the variable $attrList is in a completely different template, where the name is out of scope - perhaps you intended to pass $attrList as a parameter to the template?

In this logic

<xsl:variable name="before" select="concat('var',$counter)"/>
<xsl:variable name="after" select="$attrList[substring-after($Comp[concat('var',$counter)],',')]"/>

you appear to be constructing an element name at run-time and then substituting the value into an expression. You can't construct expressions dynamically like this; if $name contains an element name, then to select the element you don't use $name, you use *[name()=$name]. But why are you packing so much into the element name in the first place? In place of elements <var1>, <var2> etc you could use <var nr="1">, <var nr="2">, and that would make selecting them so much easier.

Another comment, I don't understand why you are constructing the value of variable $Comp dynamically (and inside a loop!) - it seems it could be a global variable with a static value.

I've identified some problems with your code, but I don't think I've got to the bottom of it: I don't understand what it's trying to do, so I've no idea whether it's even close to solving the problem for which it was written.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #3 (permalink)  
Old July 26th, 2010, 02:28 PM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Let me elaborate on what i am trying to achieve here.

Here is one object which i have coded. The attributeList has different columns associated to it. Like name/ string,datetime, booleam etc

Because it's generic data coming for different object. I am declaring the name's as a constant variable and trying to compare against values and return the values out of it.

Each object might have different set of count for names and those name's also changes. Whom i am trying to pass them as constants in order to loop through the template.

With my basis understanding of XSLT, i am trying to come up with something where i came across some issue.

To answer your questions earlier

attrList used with in the loop. giving me an error using direct path earlier. So thats the reason trying to declare above. This path never changes between objects.

I am trying to declare the number of variables in each object and loop through and trying to build var1 , var2 etc... so that i get the values from the above loop, where one set of variables will be declared at runtime based on object type.

$Comp is basically is the variable, where i am holding node set in it.

Attaching Source here

Can you elaborate on how to

Code:
<ematrix>
<creationProperties>
<release>V6R2009x.HF29(13.0.0.0)</release>
<datetime>2010-05-26T21:35:22Z</datetime>
<event>export</event>
<dtdInfo>&ematrixProductDtd;</dtdInfo>
</creationProperties>
<businessObject id="60947.5313.2980.12504">
<objectType>MPG Complaint</objectType>
<objectName>CPT10021</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
<policyRef>MPG Complaint</policyRef>
<owner>
<userRef>super13</userRef>
</owner>
<creationInfo>
<datetime>2010-05-24T16:50:39Z</datetime>
</creationInfo>
<modificationInfo>
<datetime>2010-05-26T20:48:34Z</datetime>
</modificationInfo>

<attributeList count="32">
<attribute>
<name>Complaint Originator</name>
<string>super13</string>
</attribute>
<attribute>
<name>Complaint Formally Designated Unit</name>
<string></string>
</attribute>
<attribute>
<name>MPG Complaint Priority</name>
<string>1 Urgent</string>
</attribute>
<attribute>
<name>MPG Complaint Complainant Requested Reply</name>
<boolean>TRUE</boolean>
</attribute>
<attribute>
<name>MPG Complaint Reply to Complainant</name>
<string>asdfa</string>
</attribute>
<attribute>
<name>MPG Complaint Meaningful Data Change</name>
<string><![CDATA[<table><tr><th>Event</th><th>User</th><th>Date</th><th>Type</th><th>Attribute Name / Relationship </th><th>New Value</th><th>Old Value</th></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-26T16:42:41Z</td><td>MPG Complaint Device Event</td><td>Complaint Event Cause Code</td><td>Consistency</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-26T16:42:41Z</td><td>MPG Complaint Device Event</td><td>Complaint Date of Surgery</td><td>5/10/2010 12:00:00 PM</td><td>5/10/2010 7:00:00 AM</td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-26T16:42:41Z</td><td>MPG Complaint Device Event</td><td>MPG Complaint Event Confirmed Date</td><td>5/26/2010 12:00:00 PM</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-26T16:42:41Z</td><td>MPG Complaint Device Event</td><td>MPG Complaint Event Confirmed</td><td>Yes</td><td></td></tr><tr class=even align=center><td>Disconnect</td><td>super13</td><td>2010-05-24T17:19:16Z</td><td>MPG Complaint</td><td>MPG Complaint Product</td><td>Connected 'MPG Complaint', 'CPT10021', 1'  to  'MPG Product Build', 'Build_Auto0012', -'. </td><td></td></tr><tr class=odd align=center><td>Disconnect</td><td>super13</td><td>2010-05-24T17:19:16Z</td><td>MPG Complaint</td><td>MPG Complaint Product</td><td>Connected 'MPG Complaint', 'CPT10021', 1'  to  'MPG Product Build', 'Build_Auto0009', -'. </td><td></td></tr><tr class=even align=center><td>Disconnect</td><td>super13</td><td>2010-05-24T17:19:15Z</td><td>MPG Complaint</td><td>MPG Complaint Product</td><td>Connected 'MPG Complaint', 'CPT10021', 1'  to  'MPG Product Build', 'Build_Auto0018', -'. </td><td></td></tr><tr class=odd align=center><td>Connect</td><td>super13</td><td>2010-05-24T17:12:27Z</td><td>MPG Complaint</td><td>MPG Complaint Product</td><td>Connected 'MPG Complaint', 'CPT10021', 1'  to  'MPG Product Build', 'Build_Auto0012', -'. </td><td></td></tr><tr class=even align=center><td>Connect</td><td>super13</td><td>2010-05-24T17:11:49Z</td><td>MPG Complaint</td><td>MPG Complaint Product</td><td>Connected 'MPG Complaint', 'CPT10021', 1'  to  'MPG Product Build', 'Build_Auto0009', -'. </td><td></td></tr><tr class=odd align=center><td>Connect</td><td>super13</td><td>2010-05-24T17:11:03Z</td><td>MPG Complaint</td><td>MPG Complaint Product</td><td>Connected 'MPG Complaint', 'CPT10021', 1'  to  'MPG Product Build', 'Build_Auto0018', -'. </td><td></td></tr><tr class=even align=center><td>Connect</td><td>super13</td><td>2010-05-24T17:03:03Z</td><td>MPG Complaint</td><td>MPG Complaint Product</td><td>Connected 'MPG Complaint', 'CPT10021', 1'  to  'MPG Product Build', 'Build_Auto0019', -'. </td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Event Relevant Tests Data</td><td>ASDF</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Event Other Relevant History</td><td>ASDF</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Immediate Actions Taken</td><td>Product replaced with same product</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Additional Information</td><td>ads</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Event Customer Issue Code</td><td>Color</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Date of Occurrence</td><td>05/17/2010 7:00:00 AM</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Impact to Person Affected</td><td>Extended surgery</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Event Detail</td><td>sd</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Event Timing</td><td>Kit Inspection</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Event Company Responsible For Reporting</td><td>safASDD</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Persons Affected</td><td>Patient</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Date of Surgery</td><td>05/17/2010 7:00:00 AM</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>Complaint Preceding or Contributing Events</td><td>ADS</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T17:00:08Z</td><td>MPG Complaint Nutrition Event</td><td>MPG Complaint Serious Adverse Event</td><td>Yes</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Event Relevant Tests Data</td><td>asdfa</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Surgery Time Extended</td><td>Yes</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Event Other Relevant History</td><td>sdff</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Persons Affected</td><td>Patient</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Date of Surgery</td><td>05/10/2010 7:00:00 AM</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Immediate Actions Taken</td><td>No action taken</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>MPG Complaint Secondary Event Receipt Date</td><td>05/10/2010</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Preceding or Contributing Events</td><td>asdfa</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Event Timing Detail</td><td>asdff</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Additional Information</td><td>sdff</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Event Customer Issue Code</td><td>Fire / Smoke / Burning</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>MPG Complaint Serious Adverse Event</td><td>Yes</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Date of Occurrence</td><td>05/10/2010 7:00:00 AM</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Time Surgery Was Extended</td><td>asdff</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint X-Rays or Lab Test Data Available</td><td>No</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Impact to Person Affected</td><td>Extended surgery</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Event Detail</td><td>asdf</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Event Timing</td><td>Prior To Surgery</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:58:34Z</td><td>MPG Complaint Device Event</td><td>Complaint Event Company Responsible For Reporting</td><td>asdff</td><td></td></tr><tr class=even align=center><td>Add</td><td>super13</td><td>05/24/2010 10:51:38 AM</td><td>MPG Complaint</td><td>Meaningful Data Change</td><td>sadf</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:51:38Z</td><td>MPG Complaint</td><td>Complaint Distributor Awareness Date</td><td>05/04/2010 7:00:00 AM</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:51:38Z</td><td>MPG Complaint</td><td>Complaint Summary</td><td>sdf</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:51:38Z</td><td>MPG Complaint</td><td>Complaint Compensation Details</td><td>ASDF</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:51:38Z</td><td>MPG Complaint</td><td>Complaint Customer Compensation Method</td><td>asdf</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:51:37Z</td><td>MPG Complaint</td><td>MPG Complaint Litigation</td><td>Yes</td><td></td></tr><tr class=even align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:51:37Z</td><td>MPG Complaint</td><td>Complaint Clinical Trial Complaint</td><td>Yes</td><td></td></tr><tr class=odd align=center><td>ModifyAttribute</td><td>super13</td><td>2010-05-24T16:51:37Z</td><td>MPG Complaint</td><td>Complaint External Reference</td><td>asdd</td><td></td></tr></table>]]></string>
</attribute>
<attribute>
<name>MPG Complaint Contact Alternate Phone</name>
<string></string>
</attribute>
<attribute>
<name>MPG Complaint Type Change Justification</name>
<string></string>
</attribute>
<attribute>
<name>MPG Complaint Litigation</name>
<string>Yes</string>
</attribute>
<attribute>
<name>MPG Complaint Country of Origin</name>
<string>US</string>
</attribute>
<attribute>
<name>Complaint Summary</name>
<string>sdf</string>
</attribute>
<attribute>
<name>MPG Complaint Abbott Awareness Date</name>
<datetime>2010-05-24T06:00:00Z</datetime>
</attribute>
<attribute>
<name>Notes</name>
<string>device ticket</string>
</attribute>
<attribute>
<name>MPG Complaint Reopen Count</name>
<integer>0</integer>
</attribute>
<attribute>
<name>MPG Complaint MDC Modified Date</name>
<datetime>2010-05-26T16:42:41Z</datetime>
</attribute>
<attribute>
<name>MPG Complaint Medical</name>
<string>Yes</string>
</attribute>
<attribute>
<name>MPG Complaint Integration Update Date</name>
<unknown></unknown>
</attribute>
<attribute>
<name>Complaint Source</name>
<string>Fax</string>
</attribute>
<attribute>
<name>Complaint External Reference</name>
<string>asdd</string>
</attribute>
<attribute>
<name>Complaint Litigation</name>
<string></string>
</attribute>
<attribute>
<name>Complaint Clinical Trial Complaint</name>
<string>Yes</string>
</attribute>
<attribute>
<name>Complaint Date of Awareness</name>
<datetime>2010-05-10T13:00:00Z</datetime>
</attribute>
<attribute>
<name>Complaint Supplemental Awareness Date</name>
<unknown></unknown>
</attribute>
<attribute>
<name>Complaint Distributor Awareness Date</name>
<datetime>2010-05-04T13:00:00Z</datetime>
</attribute>
<attribute>
<name>Complaint Date Closed</name>
<unknown></unknown>
</attribute>
<attribute>
<name>Complaint Invalid Rationale</name>
<string></string>
</attribute>
<attribute>
<name>Complaint Invalidator</name>
<string></string>
</attribute>
<attribute>
<name>Complaint Invalidated Date</name>
<unknown></unknown>
</attribute>
<attribute>
<name>Complaint Customer Compensation Method</name>
<string>asdf</string>
</attribute>
<attribute>
<name>Complaint Compensation Details</name>
<string>ASDF</string>
</attribute>
<attribute>
<name>Complaint Reportable Complaint</name>
<string></string>
</attribute>
<attribute>
<name>AN Complaint Report Sources</name>
<string></string>
</attribute>
</attributeList>
<stateList count="3">
<state>
<name>Create</name>
<stateStatus>enabled</stateStatus>
<actualInfo>
<datetime>2010-05-24T16:50:39Z</datetime>
</actualInfo>
<versionable/>
<startDate>
<datetime>2010-05-24T16:50:39Z</datetime>
</startDate>
<endDate>
<datetime>2010-05-24T16:50:39Z</datetime>
</endDate>
<stateDuration>
0</stateDuration>
</state>
<state>
<name>In Process</name>
<current/>
<stateStatus>enabled</stateStatus>
<actualInfo>
<datetime>2010-05-24T16:50:39Z</datetime>
</actualInfo>
<versionable/>
<startDate>
<datetime>2010-05-24T16:50:39Z</datetime>
</startDate>
<endDate>
<datetime>2010-05-26T21:35:22Z</datetime>
</endDate>
<stateDuration>
189883</stateDuration>
</state>
<state>
<name>Complete</name>
<stateStatus>enabled</stateStatus>
<versionable/>
<stateDuration>
0</stateDuration>
</state>
</stateList>
<fromRelationshipList count="14">
<relationship>
<relationshipDefRef>MPG Complaint Evaluation</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Product Evaluation</objectType>
<objectName>CPTEVAL10021-01</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
</relationship>
<relationship>
<relationshipDefRef>MPG Complaint Contact</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Contact</objectType>
<objectName>MPG-Contact-0060</objectName>
<objectRevision>2</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
<attributeList count="1">
<attribute>
<name>Complaint Contact Relationship</name>
<string>Reporter</string>
</attribute>
</attributeList>
</relationship>
<relationship>
<relationshipDefRef>MPG Complaint Medical Evaluation</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Medical Evaluation</objectType>
<objectName>CPTMEDEVAL10021-01</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
</relationship>
<relationship>
<relationshipDefRef>MPG Complaint Patient</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Patient</objectType>
<objectName>P100000023</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
</relationship>
<relationship>
<relationshipDefRef>Complaint Event</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Device Event</objectType>
<objectName>CPTEVT10021-01</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
</relationship>
<relationship>
<relationshipDefRef>Complaint Event</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Nutrition Event</objectType>
<objectName>CPTEVT10021-02</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
</relationship>
<relationship>
<relationshipDefRef>MPG Complaint Product</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Product Build</objectType>
<objectName>Build_Auto0019</objectName>
<objectRevision>-</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
<attributeList count="8">
<attribute>
<name>Complaint Product Quantity Involved</name>
<string>1</string>
</attribute>
<attribute>
<name>Complaint Product Quantity Involved UOM</name>
<string>EA</string>
</attribute>
<attribute>
<name>AN Complaint Product Daily Dose</name>
<string></string>
</attribute>
<attribute>
<name>AN Complaint Product Daily Dose UOM</name>
<string></string>
</attribute>
<attribute>
<name>MPG Complaint Product Unit Dose</name>
<string></string>
</attribute>
<attribute>
<name>MPG Complaint Product Unit Dose UOM</name>
<string></string>
</attribute>
<attribute>
<name>MPG Complaint Product Administration Route</name>
<string></string>
</attribute>
<attribute>
<name>MPG Complaint Product Dose Additional Detail</name>
<string></string>
</attribute>
</attributeList>
</relationship>
<relationship>
<relationshipDefRef>MPG Complaint Product Return</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Product Return</objectType>
<objectName>CPTRET91274721109588</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
</relationship>
<relationship>
<relationshipDefRef>MPG Complaint Product Return</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Product Return</objectType>
<objectName>CPTRET101274721147729</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
</relationship>
<relationship>
<relationshipDefRef>Complaint Team Member</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>Person</objectType>
<objectName>super13</objectName>
<objectRevision>-</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
<attributeList count="3">
<attribute>
<name>Complaint Team Role</name>
<string>Product Quality</string>
</attribute>
<attribute>
<name>MPG Acknowledged Date for Meaningful Data Change</name>
<datetime>1970-01-01T07:00:00Z</datetime>
</attribute>
<attribute>
<name>MPG Complaint MDC Acknowledged</name>
<boolean>FALSE</boolean>
</attribute>
</attributeList>
</relationship>
<relationship>
<relationshipDefRef>Action Item</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Translation</objectType>
<objectName>TRANACTTASK161274724501844</objectName>
<objectRevision></objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
</relationship>
<relationship>
<relationshipDefRef>Complaint Team Member</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>Person</objectType>
<objectName>super3</objectName>
<objectRevision>-</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
<attributeList count="3">
<attribute>
<name>Complaint Team Role</name>
<string>Medical</string>
</attribute>
<attribute>
<name>MPG Acknowledged Date for Meaningful Data Change</name>
<datetime>1970-01-01T07:00:00Z</datetime>
</attribute>
<attribute>
<name>MPG Complaint MDC Acknowledged</name>
<boolean>FALSE</boolean>
</attribute>
</attributeList>
</relationship>
<relationship>
<relationshipDefRef>MPG Complaint Contact</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Contact</objectType>
<objectName>MPG-Contact-0132</objectName>
<objectRevision>2</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
<attributeList count="1">
<attribute>
<name>Complaint Contact Relationship</name>
<string>Surgeon</string>
</attribute>
</attributeList>
</relationship>
<relationship>
<relationshipDefRef>MPG Complaint Contact</relationshipDefRef>
<relatedObject>
<businessObjectRef>
<objectType>MPG Complaint Contact</objectType>
<objectName>CPTCNT311274906913941</objectName>
<objectRevision>1</objectRevision>
<vaultRef>MPG</vaultRef>
</businessObjectRef>
</relatedObject>
<attributeList count="1">
<attribute>
<name>Complaint Contact Relationship</name>
<string>Patient</string>
</attribute>
</attributeList>
</relationship>
</fromRelationshipList>
</businessObject></ematrix>
Reply With Quote
  #4 (permalink)  
Old July 26th, 2010, 02:57 PM
mhkay's Avatar
Wrox Author
Points: 18,420, Level: 59
Points: 18,420, Level: 59 Points: 18,420, Level: 59 Points: 18,420, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,952
Thanks: 0
Thanked 289 Times in 284 Posts
Default

I think it's best if you create a simplified example, with much less data, to illustrate the problem. Show the input and the desired output of the transformation, and explain how they relate to each other.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #5 (permalink)  
Old July 26th, 2010, 03:09 PM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
<ematrix>
<BO>
<ObjectName>First</ObjectName>
<AttributeList>
<Attribute>
<name>Attr1</name>
<string>valuestring1</string>
</Attribute>
<Attribute>
<name>Attr2</name>
<datetime>valuedatetime2</datetime>
</Attribute>
<name>Attr3</name>
<boolean>valueboolean3</boolean>
</Attribute>
<AttributeList>
</BO>
<BO>
<ObjectName>Second</ObjectName>
<AttributeList>
<Attribute>
<name>Attr1</name>
<string>valuestring1</string>
</Attribute>
<Attribute>
<name>Attr2</name>
<datetime>valuedatetime2</datetime>
</Attribute>
<name>Attr3</name>
<boolean>valueboolean3</boolean>
</Attribute>
<AttributeList>
</BO>
</ematrix>
I have something like 56 object types where the attribute list changes for each type. (Attr1, Attr2, Attr3), each attribute can have either string/datetime/boolean or objecttype

I need to look for which object file coming in, then take the attribute list needed for filtering out and read the value if the name & object type matches.

The Attribute List is known upfront for each object. in the earlier XSLT Code, i list around 61 Attribute list for one object. Those will be changing for each object.

I am trying to come up with generic template by passing those name's as constant.

The output is simple text.

If one particular object type exist, then have the set of attributes written to the target, which will in text format.


Thanks for taking a look at it. Appreciate your time.
Reply With Quote
  #6 (permalink)  
Old July 26th, 2010, 04:40 PM
mhkay's Avatar
Wrox Author
Points: 18,420, Level: 59
Points: 18,420, Level: 59 Points: 18,420, Level: 59 Points: 18,420, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,952
Thanks: 0
Thanked 289 Times in 284 Posts
Default

When you say "object type", is this the same as a <BO> element in your XML file?

When you say "object file", what is this?

I'm confused by the distinction between "object type" and "object".

It looks a little to me as if the XML document you have shown is a sort of steering file for the transformation to be applied to other source files which you haven't shown. Very often the best approach to handling a "mini transformation language" like this is to transform it into XSLT code that actually does the requested transformation, rather than trying to interpret it at execution time.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #7 (permalink)  
Old July 26th, 2010, 04:47 PM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Object Name is field under BO, which refers Object Type in my terminology

Each distinct object i am referring as a object file, because i have 56 different files coming.

in my above example, first is one kind and second is one. and it goes on.

The dtd coming in just one format, they are trying to insert different objects with the same generic tag list.

In the original example, just the AttirbuteList changes for each object.

My only request, how to read the attributes between different objects by knowing the attribute value upfront like <name>Attr1</name> then
return <string>valuestring1</string> or datetime or boolean. which i am trying to declare

for the given example, xslt goes like this
first object
________________________
If ematrix/bo/objectname = "first"
if attributelist/attribute/name = "attr1"
<xsl:value-of select="attributelist/attribute/string"/>
</xsl:if>
if attributelist/attribute/name = "attr2"
<xsl:value-of select="attributelist/attribute/datetime"/>
</xsl:if>
if attributelist/attribute/name = "attr3"
<xsl:value-of select="attributelist/attribute/boolean"/>
</xsl:if>
</xsl:if>

second object
----------------------------


If ematrix/bo/objectname = "second"
if attributelist/attribute/name = "attr1"
<xsl:value-of select="attributelist/attribute/string"/>
</xsl:if>
if attributelist/attribute/name = "attr2"
<xsl:value-of select="attributelist/attribute/datetime"/>
</xsl:if>
if attributelist/attribute/name = "attr3"
<xsl:value-of select="attributelist/attribute/boolean"/>
</xsl:if>
</xsl:if>


If i continue writing, i will have to build 56 maps for this. else,i am trying to make it generic by defining name and (string/boolean/datetime) in a variable as a constant, loop through the attirbutes and find the required ones for each different object name (first, second, third ....fifty six)

Last edited by chilly; July 26th, 2010 at 05:11 PM.
Reply With Quote
  #8 (permalink)  
Old July 26th, 2010, 07:13 PM
mhkay's Avatar
Wrox Author
Points: 18,420, Level: 59
Points: 18,420, Level: 59 Points: 18,420, Level: 59 Points: 18,420, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,952
Thanks: 0
Thanked 289 Times in 284 Posts
Default

Sorry, I give up. You've made several attempts to communicate the requirements, but you just keep saying the same thing: you're not getting your message across. You still haven't shown a simple cut-down input file and the output that you want it to generate, which I asked for several messages ago.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #9 (permalink)  
Old July 26th, 2010, 08:48 PM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry for poor explanation. let me give it a shot one more time

Source
Code:
<ematrix>
<BO>
<ObjectName>First</ObjectName>
<AttributeList>
<Attribute>
<name>Attr1</name>
<string>valuestring1</string>
</Attribute>
<Attribute>
<name>Attr2</name>
<datetime>valuedatetime2</datetime>
</Attribute>
<name>Attr3</name>
<boolean>valueboolean3</boolean>
</Attribute>
<AttributeList>
</BO>
<BO>
<ObjectName>Second</ObjectName>
<AttributeList>
<Attribute>
<name>Attr1</name>
<string>valuestring1</string>
</Attribute>
<Attribute>
<name>Attr2</name>
<datetime>valuedatetime2</datetime>
</Attribute>
<name>Attr3</name>
<boolean>valueboolean3</boolean>
</Attribute>
<AttributeList>
</BO>
</ematrix>
XSLT
Code:
first object
________________________
If ematrix/bo/objectname = "first"
if attributelist/attribute/name = "attr1" 
<xsl:value-of select="attributelist/attribute/string"/>
</xsl:if>
if attributelist/attribute/name = "attr2" 
<xsl:value-of select="attributelist/attribute/datetime"/>
</xsl:if>
if attributelist/attribute/name = "attr3" 
<xsl:value-of select="attributelist/attribute/boolean"/>
</xsl:if>
</xsl:if>

second object
----------------------------


If ematrix/bo/objectname = "second"
if attributelist/attribute/name = "attr1" 
<xsl:value-of select="attributelist/attribute/string"/>
</xsl:if>
if attributelist/attribute/name = "attr2" 
<xsl:value-of select="attributelist/attribute/datetime"/>
</xsl:if>
if attributelist/attribute/name = "attr3" 
<xsl:value-of select="attributelist/attribute/boolean"/>
</xsl:if>
</xsl:if>
Target, simple text output with each attribute value
Code:
First,valuestring1,valuedatetime2,valueboolean3
Second,valuestring1,valuedatetime2,valueboolean3
The only requirement is, making it generic.

We have several different sources with several attributes. We know the attributes based on object types upfront. So, i am trying to write something generic to call this one map for all object types

Appreciate if you give one more shot at it
Reply With Quote
  #10 (permalink)  
Old July 27th, 2010, 07:02 PM
Authorized User
Points: 310, Level: 6
Points: 310, Level: 6 Points: 310, Level: 6 Points: 310, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please, any suggestion
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to loop through a HashMap in XSL? sunilnk XSLT 6 April 10th, 2017 05:09 AM
help: how can I break from xsl for-each loop ? back2grave XSLT 5 May 31st, 2012 01:03 PM
xsl:for-each loop Tomi XSLT 3 September 7th, 2006 06:35 AM
Loop in XSL NEO1976 XSLT 31 September 5th, 2006 04:39 AM
xsl template concat problem nambati XSLT 5 January 31st, 2005 03:43 PM



All times are GMT -4. The time now is 01:51 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.