Jump to content

xlst - <xsl:for-each>


genox

Recommended Posts

Hi AllI've a question on the usage of <xsl:for each> I have some source XML which I am writing an XSL script to convert to a target format (cXML) for a purchase order system. So far the XSL is using a single <xsl:template match> statement to match the root node of the source XML and is selecting each element by specifying the full path to each node, as follows:

<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"	version="1.0" xmlns:xalan="http://xml.apache.org/xslt"	xmlns:mx="http://www.ibm.com/maximo">	<xsl:output method="xml" version="1.0"		doctype-system="http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd"		indent="yes" />	<xsl:variable name="version">1.2.020</xsl:variable>	<xsl:template match="/">		<xsl:apply-templates select="mx:PublishMXPO_GOSOP" />	</xsl:template>		<xsl:template match="mx:PublishMXPO_GOSOP">		<xsl:variable name="messageID" select="@messageID" />		<xsl:variable name="timestamp" select="@creationDateTime" />		<cXML payloadID="{$messageID}" timestamp="{$timestamp}"			version="{$version}">		   <!-- *** OrderRequest starts here *** -->				<Request deploymentMode="test">		<OrderRequest>				<!-- *** OrderRequestHeader starts here *** -->				<xsl:element name="OrderRequestHeader">			<xsl:attribute name="orderDate"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:ORDERDATE"/></xsl:attribute>			<xsl:attribute name="orderID"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:PONUM"/></xsl:attribute>			<xsl:attribute name="orderType">regular</xsl:attribute>			<xsl:attribute name="orderVersion">1</xsl:attribute>			<xsl:attribute name="type">new</xsl:attribute>				<Total>		<xsl:element name="Money">			<xsl:attribute name="currency"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:TOTALCOST"/></xsl:attribute>		</xsl:element> 				</Total>...............			   </OrderRequest>			</Request>			</cXML>	</xsl:template>

This works fine for the majority of the script however at one section I use the <xsl:for-each> to loop through a section which can appear more than once. (1 or many <POLINE> elements on a <PO>. In this part of the script I use the following code

<xsl:for-each select="mx:MXPO_GOSOPSet/mx:PO/mx:POLINE"><xsl:element name="ItemOut">			<xsl:attribute name="quantity"><xsl:value-of select="mx:ORDERQTY"/></xsl:attribute>			<xsl:attribute name="lineNumber"><xsl:value-of select="mx:POLINENUM"/></xsl:attribute>						<ItemID>					<SupplierPartAuxiliaryID><xsl:value-of select="mx:ITEMNUM"/></SupplierPartAuxiliaryID> 			</ItemID>

This is fine but within this <xsl:for each> I now need to select an element which isn't within the <POLINE> tags and is in another part of the tree such as

<xsl:attribute name="currency"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:CURRENCYCODE"/></xsl:attribute>

How can I select a value within the <xsl:for-each> tags but by specifying a different node-set, i.e. an element in at a different level that the one specified in the <xsl:for-each> tags?I've tried to apply another template using <xsl: template match> but it won't allow me to next <xsl:template match> tags seemingly.Any help much appreciated, thanksSource XML

<?xml version="1.0" encoding="UTF-8"?><PublishMXPO_GOSOP xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2010-08-09T16:39:54+01:00" transLanguage="EN" baseLanguage="EN" messageID="1281368394571103050" maximoVersion="7 1 20090627-0754 V7115-149" event="1">  <MXPO_GOSOPSet>	<PO action="Replace">	  <ACQ_METHOD>Purchase</ACQ_METHOD>	  <BILLTO>BRIXHAM</BILLTO>	  <BILLTOATTN>BU - AEQ</BILLTOATTN>	  <BILLTOCOMPNAME>BLACK</BILLTOCOMPNAME>	  <BUS_LEVEL_SID />	  <BUYAHEAD>0</BUYAHEAD>	  <BUYERCOMPANY />	  <CHANGEBY changed="1">MAXADMIN</CHANGEBY>	  <CHANGEDATE changed="1">2010-08-09T16:39:54+01:00</CHANGEDATE>	  <CLEAN_INVOICE_DATE xsi:nil="true" />	  <CONTACT>Frank</CONTACT>	  <CONTRACTREFID xsi:nil="true" />	  <CONTRACTREFNUM />	  <CONTRACTREFREV xsi:nil="true" />	  <CONTRELEASESEQ xsi:nil="true" />	  <CURRENCYCODE>GBP</CURRENCYCODE>	  <CUSTOMERNUM>1489676</CUSTOMERNUM>	  <CUSTORDER_COUNTRYCODE>GB</CUSTORDER_COUNTRYCODE>	  <CUSTORDER_NUMBER />	  <DESCRIPTION>GOSOP Test Order 1 Qty 1 Item</DESCRIPTION>	  <DESCRIPTION_LONGDESCRIPTION />	  <ECOMSTATUSDATE xsi:nil="true" />	  <ENDDATE xsi:nil="true" />	  <EQUIP_LOC_ADDRESS1 />	  <EQUIP_LOC_ADDRESS2 />	  <EQUIP_LOC_ADDRESS4 />	  <EQUIP_LOC_ADDRESS5 />	  <EQUIP_LOC_ADDRESS6 />	  <EQUIP_LOC_ADDRESS7 />	  <EXCHANGEDATE changed="1">2010-08-09T00:00:00+01:00</EXCHANGEDATE>	  <EXCHANGERATE changed="1">1.0</EXCHANGERATE>	  <EXCHANGERATE2 xsi:nil="true" />	  <EXTERNALREFID />	  <FOB />	  <FOLLOWUPDATE xsi:nil="true" />	  <FREIGHTTERMS />	  <FREIGHTTERMS_LONGDESCRIPTION />	  <GOSOP_ORDER>0</GOSOP_ORDER>	  <GOSOP_PONUM />	  <GOSOP_RESPONSE_CODE />	  <GOSOP_RESPONSE_DESCRIPTION />	  <HISTORYFLAG>0</HISTORYFLAG>	  <HUB_RPA_NAME_PROD_SHIP_TO_FROM />	  <INCLUSIVE1>1</INCLUSIVE1>	  <INCLUSIVE2>1</INCLUSIVE2>	  <INCLUSIVE3>1</INCLUSIVE3>	  <INCLUSIVE4>1</INCLUSIVE4>	  <INCLUSIVE5>1</INCLUSIVE5>	  <INSPECTIONREQUIRED>0</INSPECTIONREQUIRED>	  <INTERNAL>0</INTERNAL>	  <LEASEIND>X</LEASEIND>	  <MARKVISION_ORDER>0</MARKVISION_ORDER>	  <MNETSENT />	  <NP_STATUSMEMO />	  <ORDERDATE>2010-08-09T16:38:35+01:00</ORDERDATE>	  <ORGID>IBM</ORGID>	  <ORGSID />	  <ORIGINALPONUM />	  <OWNERSYSID />	  <PAYMENTTERMS />	  <PAYONRECEIPT>0</PAYONRECEIPT>	  <PO1 />	  <PO10>0</PO10>	  <PO2 />	  <PO3 />	  <PO4 />	  <PO5 />	  <PO6 xsi:nil="true" />	  <PO7 xsi:nil="true" />	  <PO8 xsi:nil="true" />	  <PO9 xsi:nil="true" />	  <POID>262</POID>	  <PONUM>1227</PONUM>	  <POTYPE>STD</POTYPE>	  <PRIORITY>0</PRIORITY>	  <PRODCLASSNAME />	  <PRODDOMAINNNAME />	  <PRODSUBCLASSNAME />	  <PURCHASEAGENT />	  <RECEIPTS maxvalue="NONE">NONE</RECEIPTS>	  <REQUIREDDATE xsi:nil="true" />	  <SENDERSYSID>MX</SENDERSYSID>	  <SHIPTO>1 REDCLIFFE</SHIPTO>	  <SHIPTOATTN>BU - AEQ</SHIPTOATTN>	  <SHIPTOCOMPNAME>BLUE COAT</SHIPTOCOMPNAME>	  <SHIPVIA />	  <SITEID>IBMSITE</SITEID>	  <SOURCESYSID />	  <STARTDATE xsi:nil="true" />	  <STATUS changed="1" maxvalue="APPR">APPR</STATUS>	  <STATUSDATE changed="1">2010-08-09T16:39:50+01:00</STATUSDATE>	  <STATUSIFACE changed="1">1</STATUSIFACE>	  <STORELOC />	  <STORELOCSITEID />	  <SUPP_INVOICE_NUM />	  <SUPP_INV_DATE xsi:nil="true" />	  <TOTALCOST>0.0</TOTALCOST>	  <TOTALTAX1>0.0</TOTALTAX1>	  <TOTALTAX2>0.0</TOTALTAX2>	  <TOTALTAX3>0.0</TOTALTAX3>	  <TOTALTAX4>0.0</TOTALTAX4>	  <TOTALTAX5>0.0</TOTALTAX5>	  <VENDELIVERYDATE xsi:nil="true" />	  <VENDOR>SCC</VENDOR>	  <VENDORSKU />	  <POLINE>		<ASSETNUM />		<BUY_FOR_DEFRA_LINENUM>3</BUY_FOR_DEFRA_LINENUM>		<BUY_FOR_DEFRA_NUM>1</BUY_FOR_DEFRA_NUM>		<CATALOGCODE />		<CATEGORY />		<CHARGESTORE>0</CHARGESTORE>		<CLASSSTRUCTUREID />		<COMMODITY />		<COMMODITYGROUP />		<CONDITIONCODE />		<CONTRACTREFID xsi:nil="true" />		<CONTRACTREFNUM />		<CONTRACTREFREV xsi:nil="true" />		<CONTREFLINEID xsi:nil="true" />		<CONVERSION>1.0</CONVERSION>		<DEFRAAGENCY>DEFRA</DEFRAAGENCY>		<DEFRA_INCIDENT_RECORDS>IN1234</DEFRA_INCIDENT_RECORDS>		<DESCRIPTION>Encrypted Memory Stick 1GB</DESCRIPTION>		<DESCRIPTION_LONGDESCRIPTION />		<ENTERBY>MAXADMIN</ENTERBY>		<ENTERDATE>2010-08-09T16:38:35+01:00</ENTERDATE>		<ENTEREDASTASK>0</ENTEREDASTASK>		<FCPROJECTID />		<FCTASKID />		<FINCNTRLID />		<GLCREDITACCT />		<GLDEBITACCT />		<IBM_BSAP>4800011552</IBM_BSAP>		<IBM_CHG_TO_DEPT>924424</IBM_CHG_TO_DEPT>		<IBM_CUST_CONTRACT_NUM>1</IBM_CUST_CONTRACT_NUM>		<IBM_CUST_NUM>3</IBM_CUST_NUM>		<IBM_DIV>4</IBM_DIV>		<IBM_EMP_ASSET_OWNER_NUM>6</IBM_EMP_ASSET_OWNER_NUM>		<IBM_LEDGER_CODE>2</IBM_LEDGER_CODE>		<IBM_MAJOR>813</IBM_MAJOR>		<IBM_MINOR>842</IBM_MINOR>		<IBM_SUBMINOR>5</IBM_SUBMINOR>		<INSPECTIONREQUIRED>0</INSPECTIONREQUIRED>		<ISDISTRIBUTED>0</ISDISTRIBUTED>		<ISSUE>0</ISSUE>		<ITEMNUM>1071647</ITEMNUM>		<ITEMSETID>IT ITEMS</ITEMSETID>		<LEASEIND>P</LEASEIND>		<LINECOST>0.0</LINECOST>		<LINECOST2>0.0</LINECOST2>		<LINETYPE>ITEM</LINETYPE>		<LOADEDCOST>0.0</LOADEDCOST>		<LOCATION />		<MANUFACTURER>IRONKEY</MANUFACTURER>		<MKTPLCITEM>0</MKTPLCITEM>		<MODELNUM />		<MRLINENUM xsi:nil="true" />		<MRNUM />		<ORDERQTY>1.0</ORDERQTY>		<ORDERUNIT>EACH</ORDERUNIT>		<ORGID>IBM</ORGID>		<PCARDEXPDATE />		<PCARDNUM />		<PCARDTYPE />		<PCARDVERIFICATION />		<PL1 />		<PL10 />		<PL2 />		<PL3 />		<PL4 xsi:nil="true" />		<PL5 />		<PL6 />		<PL7 />		<PL8 />		<PL9 />		<PLIN1 />		<PLIN2 />		<PLIN3 />		<PLIN4 xsi:nil="true" />		<PLIN5 xsi:nil="true" />		<PLIN6 />		<PLIN7 />		<PLIN8 />		<PLIN9 />		<POLALN1 />		<POLALN2 />		<POLALN3 />		<POLALN4 />		<POLALN5 />		<POLINEID>229</POLINEID>		<POLINENUM>1</POLINENUM>		<PRLINENUM xsi:nil="true" />		<PRNUM />		<PRORATECOST xsi:nil="true" />		<PRORATESERVICE>0</PRORATESERVICE>		<RECEIPTREQD>1</RECEIPTREQD>		<RECEIPTSCOMPLETE>0</RECEIPTSCOMPLETE>		<RECEIVEDQTY xsi:nil="true" />		<RECEIVEDTOTALCOST>0.0</RECEIVEDTOTALCOST>		<RECEIVEDUNITCOST>0.0</RECEIVEDUNITCOST>		<REFWO />		<REJECTEDQTY>0.0</REJECTEDQTY>		<REMARK />		<REMARK_LONGDESCRIPTION />		<REQDELIVERYDATE xsi:nil="true" />		<REQUESTEDBY>MAXADMIN</REQUESTEDBY>		<SCHEDULEID xsi:nil="true" />		<SHIPTO />		<SHIPTOATTN />		<STORELOC>CENTRAL</STORELOC>		<SUPERVISOR />		<TAX1>0.0</TAX1>		<TAX1CODE />		<TAX2>0.0</TAX2>		<TAX2CODE />		<TAX3>0.0</TAX3>		<TAX3CODE />		<TAX4>0.0</TAX4>		<TAX4CODE />		<TAX5>0.0</TAX5>		<TAX5CODE />		<TAXED>0</TAXED>		<TOSITEID>IBMSITE</TOSITEID>		<UNITCOST>59.0</UNITCOST>		<VENDELIVERYDATE xsi:nil="true" />		<VENDORPACKCODE />		<VENDORPACKQUANTITY />		<VENDORWAREHOUSE />		<ITEM>		  <ATTACHONISSUE>0</ATTACHONISSUE>		  <CAPITALIZED>0</CAPITALIZED>		  <CLASSSTRUCTUREID>43201808</CLASSSTRUCTUREID>		  <COMMODITY />		  <COMMODITYGROUP />		  <CONDITIONENABLED>0</CONDITIONENABLED>		  <DESCRIPTION>Encrypted Memory Stick 1GB</DESCRIPTION>		  <EXTERNALREFID />		  <GROUPNAME />		  <IN19 />		  <IN20 />		  <IN21 />		  <IN22 xsi:nil="true" />		  <IN23 xsi:nil="true" />		  <IN24 />		  <IN25 />		  <IN26 />		  <IN27 />		  <INSPECTIONREQUIRED>0</INSPECTIONREQUIRED>		  <ISKIT>0</ISKIT>		  <ISSUEUNIT />		  <ITDFAMILY />		  <ITDMACHTYPE>MCTP</ITDMACHTYPE>		  <ITDMANUPARTNO>D2-S200-S01-3FIPS</ITDMANUPARTNO>		  <ITDMODEL />		  <ITEMID>17010</ITEMID>		  <ITEMNUM>1071647</ITEMNUM>		  <ITEMSETID>IT ITEMS</ITEMSETID>		  <ITEMTYPE>ITEM</ITEMTYPE>		  <LOTTYPE maxvalue="NOLOT">NOLOT</LOTTYPE>		  <MAXISSUE xsi:nil="true" />		  <METERNAME />		  <MSDSNUM />		  <ORDERUNIT />		  <OUTSIDE>0</OUTSIDE>		  <OWNERSYSID />		  <PRODUCTCODE>IMAC1/CON/105</PRODUCTCODE>		  <PRORATE>0</PRORATE>		  <ROTATING>1</ROTATING>		  <SCC_CODE>IRKME00A</SCC_CODE>		  <SEC>RDS-IMAC1</SEC>		  <SENDERSYSID>MX</SENDERSYSID>		  <SOURCESYSID />		  <SPAREPARTAUTOADD>0</SPAREPARTAUTOADD>		  <STATUS>ACTIVE</STATUS>		  <STATUSDATE>2010-08-09T15:56:18+01:00</STATUSDATE>		  <SWVIRTUALISED>0</SWVIRTUALISED>		</ITEM>	  </POLINE>	  <ADDRESS>		<ADDRESS1>New Fish Quay,</ADDRESS1>		<ADDRESS2>The Quay</ADDRESS2>		<ADDRESS3 />		<ADDRESS4>Brixham</ADDRESS4>		<ADDRESS5 />		<ADDRESS6>TQ5 8AW</ADDRESS6>		<ADDRESS7 />		<ADDRESSCODE>BRIXHAM</ADDRESSCODE>		<ADDRESSID>423</ADDRESSID>		<BUILDINGNAME>Brixham</BUILDINGNAME>		<BUILDINGSC>BRIXHAM</BUILDINGSC>		<CHANGEBY>MXINTADM</CHANGEBY>		<CHANGEDATE>2009-10-27T12:07:34+00:00</CHANGEDATE>		<DESCRIPTION />		<HASLD>0</HASLD>		<LANGCODE>EN</LANGCODE>		<ORGID>IBM</ORGID>		<REMARKS />	  </ADDRESS>	  <ADDRESS>		<ADDRESS1>5th floor,</ADDRESS1>		<ADDRESS2>1 Redcliff Street</ADDRESS2>		<ADDRESS3 />		<ADDRESS4>Bristol</ADDRESS4>		<ADDRESS5 />		<ADDRESS6>BS1 6NP</ADDRESS6>		<ADDRESS7 />		<ADDRESSCODE>1 REDCLIFFE</ADDRESSCODE>		<ADDRESSID>726</ADDRESSID>		<BUILDINGNAME>1 Redcliffe (Ex Ca/CRC site)</BUILDINGNAME>		<BUILDINGSC>1 REDCLIFFE</BUILDINGSC>		<CHANGEBY>MXINTADM</CHANGEBY>		<CHANGEDATE>2009-10-27T12:50:06+00:00</CHANGEDATE>		<DESCRIPTION />		<HASLD>0</HASLD>		<LANGCODE>EN</LANGCODE>		<ORGID>IBM</ORGID>		<REMARKS>(Ex CA/CRC site)</REMARKS>	  </ADDRESS>	  <PERSON>		<ACCEPTINGWFMAIL>1</ACCEPTINGWFMAIL>		<ADDRESSLINE1 />		<ADDRESSLINE2 />		<ADDRESSLINE3 />		<BILLTOADDRESS />		<BIRTHDATE xsi:nil="true" />		<CALTYPE />		<CITY />		<COUNTRY />		<COUNTY />		<COURTESYTITLE />		<DELEGATE />		<DELEGATEFROMDATE xsi:nil="true" />		<DELEGATETODATE xsi:nil="true" />		<DEPARTMENT />		<DISPLAYNAME>Owen Davies</DISPLAYNAME>		<DROPPOINT />		<EMPLOYEETYPE />		<EXTENSION />		<EXTERNALREFID />		<FIRSTNAME>Owen</FIRSTNAME>		<HIREDATE xsi:nil="true" />		<HOMEWORKER>0</HOMEWORKER>		<IBM_DEPTAGENCY>AEQ</IBM_DEPTAGENCY>		<IBM_GROUPDIRECTORATE />		<IBM_GROUPPRODIVISION />		<IBM_IBMORGSTRUCTUREID xsi:nil="true" />		<IBM_ORGANISATION>DEFRA</IBM_ORGANISATION>		<IMID>Owen.Davies@xxxx.org.uk</IMID>		<IM_ID />		<ITDCLIENTUSERID>X932447</ITDCLIENTUSERID>		<ITDCOMMENT />		<JOBCODE />		<LANGUAGE />		<LASTEVALDATE xsi:nil="true" />		<LASTNAME>Davies</LASTNAME>		<LOCALE />		<LOCATION>NE READG COLEY</LOCATION>		<LOCATIONORG>IBM</LOCATIONORG>		<LOCATIONSITE>IBMSITE</LOCATIONSITE>		<LOCTOSERVREQ>1</LOCTOSERVREQ>		<NEXTEVALDATE xsi:nil="true" />		<OWNERGROUP />		<OWNERSYSID />		<PCARDEXPDATE />		<PCARDNUM />		<PCARDTYPE />		<PCARDVERIFICATION />		<PERSONID>BU - AEQ</PERSONID>		<PERSONREMARKS />		<PERSONUID>25173</PERSONUID>		<POSTALCODE />		<PRIMARYSMS />		<REGIONDISTRICT />		<SEARCHLANGUAGE />		<SECANSWER />		<SECURITYANSWER />		<SECURITYQUESTION />		<SENDERSYSID>MX</SENDERSYSID>		<SHIPTOADDRESS>NE READG COLEY</SHIPTOADDRESS>		<SOURCESYSID />		<SPECIFICNEEDS>0</SPECIFICNEEDS>		<SPECIFICNEEDSDESC />		<STATEPROVINCE />		<STATUS maxvalue="ACTIVE">ACTIVE</STATUS>		<STATUSDATE>2009-10-28T16:34:43+00:00</STATUSDATE>		<SUPERVISOR />		<TERMINATIONDATE xsi:nil="true" />		<TIMEZONE />		<TITLE />		<TRANSEMAILELECTION maxvalue="NEVER">NEVER</TRANSEMAILELECTION>		<VIP xsi:nil="true" />		<WFMAILELECTION />		<WOPRIORITY xsi:nil="true" />		<PHONE>		  <ISPRIMARY>1</ISPRIMARY>		  <PHONEID>6044424</PHONEID>		  <PHONENUM>unk</PHONENUM>		  <TYPE />		</PHONE>	  </PERSON>	.........	</PO>  </MXPO_GOSOPSet></PublishMXPO_GOSOP>

XSL script

<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"	version="1.0" xmlns:xalan="http://xml.apache.org/xslt"	xmlns:mx="http://www.ibm.com/maximo">	<xsl:output method="xml" version="1.0"		doctype-system="http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd"		indent="yes" />	<xsl:variable name="version">1.2.020</xsl:variable>	<!-- 		doctype-system="/maxxsl/cXML.dtd" -->	<xsl:template match="/">		<xsl:apply-templates select="mx:PublishMXPO_GOSOP" />	</xsl:template>	<xsl:template match="mx:PublishMXPO_GOSOP">		<xsl:variable name="messageID" select="@messageID" />		<xsl:variable name="timestamp" select="@creationDateTime" />		<cXML payloadID="{$messageID}" timestamp="{$timestamp}"			version="{$version}">								<!-- *** OrderRequest starts here *** -->				<Request deploymentMode="test">		<OrderRequest>				<!-- *** OrderRequestHeader starts here *** -->				<xsl:element name="OrderRequestHeader">			<xsl:attribute name="orderDate"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:ORDERDATE"/></xsl:attribute>			<xsl:attribute name="orderID"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:PONUM"/></xsl:attribute>			<xsl:attribute name="orderType">regular</xsl:attribute>			<xsl:attribute name="orderVersion">1</xsl:attribute>			<xsl:attribute name="type">new</xsl:attribute>					<Total>		<xsl:element name="Money">			<xsl:attribute name="currency"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:TOTALCOST"/></xsl:attribute>		</xsl:element> 				</Total>				<!-- *** Contact section start *** -->				<Contact>			<Name xml:lang="en"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:COMPCONTACT/mx:CONTACT"/></Name>			<Email><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:COMPCONTACT/mx:EMAIL"/></Email>			<Phone>			<TelephoneNumber>			<CountryCode isoCountryCode="US"/>			<AreaOrCityCode>			<xsl:value-of select="substring(mx:MXPO_GOSOPSet/mx:PO/mx:COMPCONTACT/mx:VOICEPHONE, 1, 5)"/>			</AreaOrCityCode>			<Number>			<xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:COMPCONTACT/mx:VOICEPHONE"/>			</Number>			</TelephoneNumber>			</Phone>		</Contact>				<!-- *** Contact section end *** --><!-- *** ItemOut starts here *** -->				<!-- loop through all polines -->						<!--<xsl:apply-templates select="mx:PublishMXPO_GOSOP" />-->		<xsl:for-each select="mx:MXPO_GOSOPSet/mx:PO/mx:POLINE">		<xsl:element name="ItemOut">			<xsl:attribute name="quantity"><xsl:value-of select="mx:ORDERQTY"/></xsl:attribute>			<xsl:attribute name="lineNumber"><xsl:value-of select="mx:POLINENUM"/></xsl:attribute>						<ItemID>						<SupplierPartAuxiliaryID><xsl:value-of select="mx:ITEMNUM"/></SupplierPartAuxiliaryID> 			</ItemID>						<ItemDetail>				<UnitPrice>					<xsl:element name="Money">						<xsl:attribute name="alternateCurrency"></xsl:attribute>						<xsl:attribute name="alternateAmount"></xsl:attribute>						<xsl:attribute name="currency"><xsl:value-of select="mx:MXPO_GOSOPSet/mx:PO/mx:CURRENCYCODE"/></xsl:attribute>										<xsl:value-of select="mx:UNITCOST"/> 					</xsl:element> 					</UnitPrice>			  </xsl:element>		</xsl:for-each>					</OrderRequest>			</Request>			</cXML>	</xsl:template></xsl:stylesheet>					   </ItemDetail>

Current output XML

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd"><cXML xmlns:mx="http://www.ibm.com/maximo" xmlns:xalan="http://xml.apache.org/xslt" version="1.2.020" timestamp="2010-08-09T16:39:54+01:00" payloadID="1281368394571103050"><Request deploymentMode="test"><OrderRequest><OrderRequestHeader orderDate="2010-08-09T16:38:35+01:00" orderID="1227" orderType="regular" orderVersion="1" type="new"><Total><Money currency="0.0"/></Total><Contact><Name xml:lang="en">Frank</Name><Email>frank@scc.com</Email><Phone><TelephoneNumber><CountryCode isoCountryCode="US"/><AreaOrCityCode>01254</AreaOrCityCode><Number>01254 986522</Number></TelephoneNumber></Phone></Contact></OrderRequestHeader><ItemOut quantity="1.0" lineNumber="1"><ItemID><SupplierPartAuxiliaryID>1071647</SupplierPartAuxiliaryID></ItemID><ItemDetail><UnitPrice><Money alternateCurrency="" alternateAmount="" currency="">59.0</Money></UnitPrice><Description xml:lang="en">Encrypted Memory Stick 1GB</Description><UnitOfMeasure>EACH</UnitOfMeasure><Classification domain="UNSPSC">43211603</Classification><ManufacturerPartID></ManufacturerPartID></ItemDetail></ItemOut></OrderRequest></Request></cXML>

Link to comment
Share on other sites

XPath allows you to "navigate" to all nodes, you can go to the parent node with ".." or "parent::node()", you can go to an ancestor "foo" element with "ancestor::foo", you can access the root node with "/" and there are several other options, try an XPath tutorial. I think in your case you simply want

<xsl:value-of select="../mx:CURRENCYCODE"/>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...