Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2011, 08:08 AM
Registered User
 
Join Date: Jul 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default XSLT fix

Hello,

I am quite new to XML/XSLT and I face a "little" problem regarding XSLT processing. I have to generate a B2MML file using an XSL Transformation.

I synthesized the example into files bellow.
The XML file is :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<ROOTE_NODE xmlns="http://xmlns.example.com/unique/default/namespace/1311054750884">
	<ID1>val_id1</ID1>
	<ID2>val_id2</ID2>	
	<DATAAREA>
		<item>		
			<KEY1>1000</KEY1>
			<QTY_KEY1>13.10</QTY_KEY1>	
			<KEY2>0010</KEY2>
			<KEY3>00001</KEY3>
			<PrototypeID>112233</PrototypeID>
			<H-Code>S023</H-Code>					
		</item>
		<item>
			<KEY1>1000</KEY1>
			<QTY_KEY1>13.10</QTY_KEY1>
			<KEY2>0010</KEY2>
			<KEY3>00002</KEY3>
			<PrototypeID>112244</PrototypeID>
			<H-Code>S022</H-Code>				
		</item>
		<item>
			<KEY1>1001</KEY1>
			<QTY_KEY1>19.50</QTY_KEY1>
			<KEY2>0010</KEY2>
			<KEY3>00001</KEY3>
			<PrototypeID>112233</PrototypeID>
			<H-Code>M001</H-Code>			
		</item>		
	</DATAAREA>
</ROOTE_NODE>
The XSLT is :

Code:
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amg="Pelican@Plant1" xmlns:bml="http://www.wbf.org/xml/b2mml-v02" xmlns:oag="http://www.openapplications.org/oagis" xmlns:sit="http://www.siemens.com/ad/mes/b2mml-v02-SITExt-1.0" xmlns:xsi="http://www.siemens.com/ad/mes/b2mt-1.0 C:\DATA_EXCHANGE\B2MT\B2MT_Schemas\AMG_ProductionSchedule.xsd" version="2.0">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="ROOTE_NODE">
		<SyncProductionSchedule>
			<oag:ApplicationArea>
				<oag:Sender>
					<oag:LogicalId>
						<xsl:value-of select="ID1"/>
					</oag:LogicalId>
					<oag:Component>
						<xsl:value-of select="ID2"/>
					</oag:Component>
				</oag:Sender>
			</oag:ApplicationArea>
			<DataArea>
				<xsl:apply-templates select="DATAAREA"/>
			</DataArea>
		</SyncProductionSchedule>
	</xsl:template>
	<xsl:template match="DATAAREA">
		<xsl:for-each-group select="item" group-by="KEY1">
			<bml:ProductionSchedule>
				<bml:ProductionRequest>
					<bml:ID_1>
						<xsl:value-of select="KEY1"/>
					</bml:ID_1>
					<bml:Any>
						<sit:ProductionRequestExtension>
							<sit:Quantity>
								<bml:QuantityString>
									<xsl:value-of select="QTY_KEY1"/>
								</bml:QuantityString>
								<bml:DataType>
									<xsl:text>float</xsl:text>
								</bml:DataType>
							</sit:Quantity>
						</sit:ProductionRequestExtension>
						<amg:ProductionRequestExtension>
							<xsl:for-each-group select="current-group()" group-by="KEY2">
								<amg:ID_2>
									<xsl:value-of select="KEY2"/>
								</amg:ID_2>
								<amg:Order>
									<xsl:for-each select="current-group()">
										<amg:ID_3>
											<xsl:value-of select="KEY3"/>
											<amg:Prototypes>
												<amg:PrototypeID>
													<xsl:value-of select="PrototypeID"/>
												</amg:PrototypeID>
												<amg:H-Code>
													<xsl:value-of select="H-Code"/>
												</amg:H-Code>
											</amg:Prototypes>
										</amg:ID_3>
									</xsl:for-each>
								</amg:Order>
							</xsl:for-each-group>
						</amg:ProductionRequestExtension>
					</bml:Any>
				</bml:ProductionRequest>
			</bml:ProductionSchedule>
		</xsl:for-each-group>
	</xsl:template>
</xsl:transform>

Everything works perfectly if the XML file does not contain the text in red. However, we use Tibco to automatically extract data, create the XML and to apply the transformation and the red part is inserted in the process (at XML creation). How to correct my XSLT file in order to successfully process the XML with red part included ?

Thank you very much
Doru
 
Old July 20th, 2011, 08:24 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You need to specify the namespace in your XSLT, and then e.g. xnlns:ns1="http://xmlns.example.com/unique/default/namespace/1311054750884" and then match using that prefix, e.g. match="ns1:ROOTE_NODE".

If you don't know namespace, or it changes each time then you could match based on local name only, e.g. match="*[local-name()='ROOTE_NODE']". This isn't very efficient.

If you are using XSLT 2.0 then you could pre-process the code to remove all namespaces, then reprocess, or you can use namespace wildcards as well, e.g. match="*:ROOTE_NODE".

Sam
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
dorub (July 22nd, 2011)
 
Old July 21st, 2011, 08:59 AM
Registered User
 
Join Date: Jul 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

hi Sam,

very useful your hint. Pointed me to the right direction regarding namespaces. Your solution didn't work for me but I was able to solve it by declaring the 'xpath-default-namespace' (I'm using XSLT 2.0).
Code:
xpath-default-namespace="http://xmlns.example.com/unique/default/namespace/1311054750884"
thanks,
Doru





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Code fix HemaRaj Javascript 5 January 31st, 2008 04:41 PM
please fix this function keyvanjan ASP.NET 2.0 Professional 4 September 18th, 2007 08:01 AM
XSLT Newbie needs help... Should be easy fix! C4 XSLT 1 November 21st, 2005 04:11 AM
Need xref Fix ~Bean~ SQL Language 2 October 5th, 2005 02:45 PM
Help! How do I fix this? missusfinz Crystal Reports 1 April 1st, 2005 12:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.