This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Losing xsl:param values within a called template for-each loop


Greg, 
Here is the xml complete source xml doc(yet still an example), I shortened
it last time...

<Message id="ANO2001-12-13-11:34:07.419" version="1.4" bodyType="IAA-XML"
timeStampCreated="2001-12-13-11:34:07.419" sourceLogicalId="HUB"
destinationLogicalId="I3" authenticationId="">
	<CrfActionGroup destinationLogicalId="I3">
		<CommandReference refid="CMD1"/>
		<KeyGroup id="K1" keyGroupType="PARTY">
			<AlternateId value="2001-07-25-00.00.00.003170"
sourceLogicalId="ANO" state="exists"/>
			<AlternateId value="826620515239830"
sourceLogicalId="I3" state="exists"/>
		</KeyGroup>
		<KeyGroup id="K2" keyGroupType="PARTY">
			<AlternateId value="2001-07-25-00.00.00.003171"
sourceLogicalId="ANO" state="exists"/>
			<AlternateId value="953689412580434"
sourceLogicalId="I3" state="exists"/>
		</KeyGroup>
	</CrfActionGroup>
	<COMMAND>
		<AddPelpPolicyRequest cmdType="request"
cmdMode="alwaysRespond">
			<Individual>
				<KeyGroup refid="K1"/>
				<partyId/>
			</Individual>
			<LineOfBusiness>
				<PartyRole>
					<KeyGroup refid="K1"/>
					<partyId>PARTY ID</partyId>
				</PartyRole>
				<PartyRole>
					<KeyGroup refid="K2"/>
					<partyId/>
				</PartyRole>
			</LineOfBusiness>
		</AddPelpPolicyRequest>
	</COMMAND>
</Message>

As far as the naming goes, unfortunatley, I cannot change any names of the
elements here, this is a spec that was designed for messages between our
systems, and at this time is out of my control, otherwise, I would definitly
change the names of the <KeyGroup> elements.

Here is the desired output...The only necessary change is the added value in
the <partyId> elements for the <KeyGroup> elements under the <Command> node
set...Where <KeyGroup refid="K1"> below, I need to obtain the <KeyGroup id =
"K1"> matched element from above (source document) where its child
<AlternateID> has an attribute value of @sourceLogicalId=I3.  When I find
this child, I need to get its @value value, and put it in the text of the
output result <partyId> sibling of the output result <KeyGroup> elements
seen below...This is the desired output...

<Message id="ANO2001-12-13-11:34:07.419" version="1.4" bodyType="IAA-XML"
timeStampCreated="2001-12-13-11:34:07.419" sourceLogicalId="HUB"
destinationLogicalId="I3" authenticationId="">
	<COMMAND>
		<AddPelpPolicyRequest cmdType="request"
cmdMode="alwaysRespond">
			<Individual>
				<KeyGroup refid="K1"/>
				<partyId>826620515239830</partyId>
			</Individual>
			<LineOfBusiness>
				<PartyRole>
					<KeyGroup refid="K1"/>
					<partyId>826620515239830</partyId>
<!-- this is the @value value of the <AlternateId> child element from the
source xml doc where its parent <KeyGroup> has an attribute value (@id
="K1") that matches this <KeyGroup> elements @refid ="K1"-->
				</PartyRole>
				<PartyRole>
					<KeyGroup refid="K2"/>
					<partyId>953689412580434</partyId>
<!-- this is the @value value of the <AlternateId> child element from the
source xml doc where its parent <KeyGroup> has an attribute value (@id =
"K2") that matches this <KeyGroup> elements @refid = "K2"-->
				</PartyRole>
			</LineOfBusiness>
		</AddPelpPolicyRequest>
	</COMMAND>
</Message>

There are an indeterminate number of KeyGroups for any given message, this
is just an example that happens to contain 2 KeyGroup type elements (K1 &
K2)...

-----Original Message-----
From: Greg Faron [mailto:gfaron@integretechpub.com]
Sent: Monday, May 13, 2002 6:22 PM
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] Losing xsl:param values within a called template
for-each loop


Comments sprinkled below...

At 03:51 PM 5/13/2002, you wrote:
>Here is the sample xml doc...
><CrfActionGroup destinationLogicalId="I3">
>                 <CommandReference refid="CMD1"/>
>                 <KeyGroup id="K1" keyGroupType="PARTY"> <!-- get the
>keygroup where its AlternateId child has a @sourceLogicalID equal to I3-->
>                         <AlternateId value="2001-07-25-00.00.00.003170"
>sourceLogicalId="ANO" state="exists"/>
>                         <AlternateId value="826620515239830"
>sourceLogicalId="I3" state="exists"/> <!-- pass the @value to the named
>template-->
>                         <UUID>1155</UUID>
>                 </KeyGroup>
>                 <KeyGroup id="K2" keyGroupType="PARTY">
>                         <AlternateId value="2001-07-25-00.00.00.003171"
>sourceLogicalId="ANO" state="exists"/>
>                         <AlternateId value="953689412580434"
>sourceLogicalId="I3" state="exists"/>
>                         <UUID>1154</UUID>
>                 </KeyGroup>
>         </CrfActionGroup>
>         <COMMAND>
>                 <AddPelpPolicyRequest cmdType="request"
>cmdMode="alwaysRespond">
>                         <Individual>
>                                 <KeyGroup refid="K1"/> <!-- need to match
>this refid value to the id value of the CrfActionGroup KeyGroup element
seen
>above-->
>                                 <partyId/> <!-- this needs to become the
>value of the @value for the <AlternateID> element where its
@sourceLogicalID
>= I3 as seen above-->
>                         </Individual>
>                         <LineOfBusiness>
>                                 <PartyRole>
>                                         <KeyGroup refid="K1"/>
>                                         <partyId>PARTY ID</partyId>
>                                 </PartyRole>
>                                 <PartyRole>
>                                         <KeyGroup refid="K2"/>
>                                         <partyId/>
>                                 </PartyRole>
>                         </LineOfBusiness>
>                 </AddPelpPolicyRequest>
>         </COMMAND>


   I'm assuming you merely forgot to enter a root node, as the above is a 
not valid XML document.  I'm using <root>...</root> to envelop the above.


>Here is the xsl template....
>
><xsl:template match="KeyGroup">  <!-- search through first set of KeyGroup
>elements -->


   This match will match the KeyGroup elements in the top of your XML 
snippit, as well as those contained in your COMMAND element.  Are you sure 
that you want to name them the same?


>                 <xsl:for-each select="AlternateId">
>                         <xsl:if test=" @sourceLogicalId = 'I3' "> <!-- get
>its child with the attribute value specified-->
>                                 <xsl:call-template name="command"> <!-- if
>the test is true, call the named template passing the parms-->
>                                         <xsl:with-param name="keyvalue"
>select="@value"/>
>                                         <xsl:with-param name="keyid"
>select="../@id"/>
>                                 </xsl:call-template>
>                         </xsl:if>
>                 </xsl:for-each>
>         </xsl:template>
>
>         <xsl:template name="command" match="COMMAND">


   I'm not sure that this is legal, but I'm pretty sure it wasn't 
intended.  When you call the template, it will not have any simultaneous 
match to a COMMAND element that you seem to try to access.  Likewise, when 
you match the COMMAND element, you won't have any parameters to 
output.  You need to pick one method of accessing it, and go with that.


>                 <xsl:param name="keyvalue"/>
>                 <xsl:param name="keyid"/>
>                         <xsl:if test="($keyvalue != '') and ($keyid !=
'')">
>                         <!-- TEST VALUES These output correctly here-->
>                         <xsl:value-of select="$keyvalue"></xsl:value-of>
>                         <xsl:value-of select="$keyid"></xsl:value-of>
>                                 <xsl:for-each
select="descendant::KeyGroup">
><!--search the KeyGroup descendants of the COMMAND element-->
>                                         <!-- LOSING THE PARAM VALUES
HERE-->
>                                         <xsl:if test="@refid = '$keyid'">
><!-- if the refId = parm passed in, then output the other parm value passed
>in-->
>                                                 partyId <xsl:value-of
>select="$keyvalue"/>
>                                         </xsl:if>
>                                 </xsl:for-each>
>                         </xsl:if>
>         </xsl:template>


   Could you post an example of what your desired output is, before I spend 
any time stepping though your code and second-guessing it?



Greg Faron
Integre Technical Publishing Co.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the sender and postmaster@amica.com.
**********************************************************************
 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]