RE: Output from node traversal not processing correctly

"Tim Hibbs" <[email protected]> Wed, 17 Feb 2010 12:25:18 -0600
Newsgroups gmane.text.xml.xalan.java.user
Message-ID <06ACD6C2DAA98749B533845A78D451AF05C85C3E@MEMEXCH07V.corp.ds.fedex.com>
Nathan,
 
Thanks so much for the insights; not quite there yet in my
understanding...
 
First things first - xalan-j-users list protocol: It appears my
deficiency relates to general XSLT knowledge. Is it appropriate to copy
the list on any follow-up questions here, even though they may not
directly relate to xalan? I'm doing so this time under the presumption
the answer is "Yes", but I also don't want to pollute inboxes with
chaff. On the other hand, I want to ensure that those who might benefit
from the exchange can do so. 
 
Second, with changes you implied in your response, I tried several
variations. I'm still missing something, probably elemental, of
importance. Additional guidance would be most welcome...
 
I now have the following, representative of all the variations I tried:

XML: (no change)
 
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.fedex.com/schemas/freightRateQuotation">
 <xsl:template match="/">
  <html>
   <body>
     <xsl:apply-templates select="To" />
   </body>
  </html>
 </xsl:template>
 
 <xsl:template match="To">
  To: <xsl:value-of select="."/>
 </xsl:template>
</xsl:stylesheet>
 
Actual Result:
<?xml version="1.0" encoding="UTF-8"?><html
xmlns="http://www.fedex.com/schemas/freightRateQuotation"><body/></html>
 
Logging information (from "Debugger Interface":
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #3, Column #26: template match='/' 
STARTDOCUMENT
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #4, Column #9: html
STARTELEMENT: html
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #5, Column #10: body
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #6, Column #41: apply-templates
Selected source node '#document'
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #6, Column #41: apply-templates, select='null': 
     [empty node list]
STARTELEMENT: body
ENDELEMENT: body
ENDELEMENT: html
ENDDOCUMENT
 
Thanks in advance for the consideration and attention.

Tim Hibbs
FedEx Services
350 Spectrum Loop
Colorado Springs, CO 80921
719-484-2131

 

________________________________

From: Nathan Nadeau [mailto:[email protected]] 
Sent: Wednesday, February 17, 2010 10:16 AM
To: Tim Hibbs
Cc: [email protected]
Subject: Re: Output from node traversal not processing correctly


Tim,

What's happening is you're triggering the default templates that are
provided by the XSLT processor that match element and text  nodes when
you call <xsl:apply-templates/>. There are built in rules provided by
the XSLT processor that match the different node types. The default rule
for element nodes is to simply call <xsl:apply-templates/> again on its
children nodes. The default rule for a text node is to print out the
text to the output.

So when you call <xsl:apply-templates/> in your XSL, it's actually
matching all the nodes, not just the <To> element, and it's firing the
default template for everything but the <To> element, which fires the
more specific template that matches the <To> element. This has the
effect of printing out out all the text of each of the elements.

And actually it looks like it might not be matching the <To> element
either, because it has a namespace in the source XML document that
you're not specifying in your XSL. Your namespaces need to match between
your XSL and your input XML document, otherwise the processor will not
match it.

Nathan Nadeau

Tim Hibbs wrote: 

	Hi - I'm requesting some basic assistance with an XSL processing
problem. I would think this is a simple issue to resolve, but I haven't
had much luck. 
	Any asistance would be greatly appreciated.
	 
	Issue: Node contents not being output as expected.
	 
	Execution Context: 
	    - eclipse 3.5.1, running a 2.x EJB on a local Weblogic 10.3
server, using Java JRE jdk16.0_17
	        - using eclipse Java EE Developer Tools, Oracle Weblogic
Server Tools, Oracle Common Tools
	        - CLASSPATH overridden to force xalan.jar, xml-apis.jar,
serializer.jar, and xercesImpl.jar before weblogic.jar
	            - to allow instantiation of a proper
TransformerFactory (not Weblogic's version) and use of the "debugger
Interface" (http://xml.apache.org/xalan-j/usagepatterns.html#debugging)
	    - Xalan-j_2_7_1
	    - Input is a DOMSource, wrapping an org.w3c.dom.Document.
	        - Relevant code: aTransformer.transform(aDOMSource, new
StreamResult(aFileOutputStream)); "aTransformer" is instanceof
TransformerImpl
	 
	Personal Context:
	    - New to XSL, Xalan. Have taken care to try all options I
can think of before soliciting for assistance here. Don't fully
understand Debugger outputs (below).
	 
	Anticipated Result:
	<?xml version="1.0" encoding="UTF-8"?>
	<html>
	    <body>
	       To:    John Customer
	    </body>
	</html>
	
	Actual Result:
	<?xml version="1.0" encoding="UTF-8"?><html>
	<body>Customer Company123 Main StreetAnytownCO80134USJohn
CustomerFedex02/02/1012:01:[email protected]
12345678Salt Lake CityUT84106US</body>
	</html>
	 
	XML:
	<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
	<tFreightRateQuotation
xmlns="http://www.fedex.com/schemas/freightRateQuotation">
	   <AccountInformation>
	      <CompanyName>Customer Company</CompanyName>
	      <Address1>123 Main Street</Address1>
	      <City>Anytown</City>
	      <State>CO</State>
	      <Postal>80134</Postal>
	      <Country>US</Country>
	   </AccountInformation>
	   <CommonData>
	      <To>John Customer</To>
	      <From>Fedex</From>
	      <HeaderDate>02/02/10</HeaderDate>
	      <HeaderTime>12:01:00</HeaderTime>
	      <FaxNumber>3031234567</FaxNumber>
	      <EmailAddress>[email protected]</EmailAddress>
	   </CommonData>
	   <RateQuote>
	      <QuoteNumber>1 12345678</QuoteNumber>
	      <OriginAddress>
	         <OriginCity>Salt Lake City</OriginCity>
	         <OriginState>UT</OriginState>
	         <OriginPostal>84106</OriginPostal>
	         <OriginCountry>US</OriginCountry>
	      </OriginAddress>
	   </RateQuote>
	</tFreightRateQuotation>
	
	XSL:
	<?xml version="1.0" encoding="UTF-8"?>
	<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	    <xsl:template match="/">
	        <html>
	            <body>
	                <xsl:apply-templates />
	            </body>
	        </html>
	    </xsl:template>
	
	    <xsl:template match="To">
	            To: <xsl:value-of select="."/>
	        <xsl:apply-templates/>
	    </xsl:template>
	</xsl:stylesheet>
	 
	Logging information (from "Debugger Interface",
http://xml.apache.org/xalan-j/usagepatterns.html#debugging
<http://xml.apache.org/xalan-j/usagepatterns.html#debugging> ):
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #3, Column #26: template match='/' 
	STARTDOCUMENT
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #4, Column #9: html
	STARTDOCUMENT
	STARTELEMENT: html
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #5, Column #10: body
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #6, Column #29: apply-templates
	Selected source node '#document'
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #6, Column #29: apply-templates, select='null': 
	     10001: tFreightRateQuotation
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'tFreightRateQuotation'
	(default rule) apply-templates, select='null': 
	     10004: AccountInformation
	     10011: CommonData
	     1001e: RateQuote
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'AccountInformation'
	(default rule) apply-templates, select='null': 
	     10005: CompanyName
	     10007: Address1
	     10009: City
	     1000b: State
	     1000d: Postal
	     1000f: Country
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'CompanyName'
	(default rule) apply-templates, select='null': 
	     10006: #text
	STARTELEMENT: body
	CHARACTERS: Customer Company
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'Address1'
	(default rule) apply-templates, select='null': 
	     10008: #text
	CHARACTERS: 123 Main Street
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'City'
	(default rule) apply-templates, select='null': 
	     1000a: #text
	CHARACTERS: Anytown
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'State'
	(default rule) apply-templates, select='null': 
	     1000c: #text
	CHARACTERS: CO
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'Postal'
	(default rule) apply-templates, select='null': 
	     1000e: #text
	CHARACTERS: 80134
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'Country'
	(default rule) apply-templates, select='null': 
	     10010: #text
	CHARACTERS: US
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'CommonData'
	(default rule) apply-templates, select='null': 
	     10012: To
	     10014: From
	     10016: HeaderDate
	     10018: HeaderTime
	     1001a: FaxNumber
	     1001c: EmailAddress
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'To'
	(default rule) apply-templates, select='null': 
	     10013: #text
	CHARACTERS: John Customer
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'From'
	(default rule) apply-templates, select='null': 
	     10015: #text
	CHARACTERS: Fedex
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'HeaderDate'
	(default rule) apply-templates, select='null': 
	     10017: #text
	CHARACTERS: 02/02/10
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'HeaderTime'
	(default rule) apply-templates, select='null': 
	     10019: #text
	CHARACTERS: 12:01:00
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'FaxNumber'
	(default rule) apply-templates, select='null': 
	     1001b: #text
	CHARACTERS: 3031234567
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'EmailAddress'
	(default rule) apply-templates, select='null': 
	     1001d: #text
	CHARACTERS: [email protected]
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'RateQuote'
	(default rule) apply-templates, select='null': 
	     1001f: QuoteNumber
	     10021: OriginAddress
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'QuoteNumber'
	(default rule) apply-templates, select='null': 
	     10020: #text
	CHARACTERS: 1 12345678
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'OriginAddress'
	(default rule) apply-templates, select='null': 
	     10022: OriginCity
	     10024: OriginState
	     10026: OriginPostal
	     10028: OriginCountry
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'OriginCity'
	(default rule) apply-templates, select='null': 
	     10023: #text
	CHARACTERS: Salt Lake City
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'OriginState'
	(default rule) apply-templates, select='null': 
	     10025: #text
	CHARACTERS: UT
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'OriginPostal'
	(default rule) apply-templates, select='null': 
	     10027: #text
	CHARACTERS: 84106
	null Line #0, Column #0: template match='*' 
	
file:///D:/workspaces/3.5/2010-June-load/1SRC_FAX/FaxEjb/XML/rateQuoteXm
lToPdf-FO.xsl Line #0, Column #0: apply-templates
	Selected source node 'OriginCountry'
	(default rule) apply-templates, select='null': 
	     10029: #text
	CHARACTERS: US
	ENDELEMENT: body
	ENDELEMENT: html
	ENDDOCUMENT
	 
	Observations:
	    - Nodes seem to be traversed properly.
	    - Line # and Column # don't increment after initial
apply-templates
	 
	Thanks in advance for your insights!

	Tim Hibbs
	FedEx Services
	350 Spectrum Loop
	Colorado Springs, CO 80921
	719-484-2131

	 


-- 
Nathan Nadeau
[email protected]
Software Development
Gleim Publications, Inc.
http://www.gleim.com